Transcript Slide 1

Macros in action
Martin Hejtmanek
CTO, Kentico software s.r.o.
Agenda
•
•
•
•
•
•
•
History of macros
Macro types
Macro parameters
Examples, tips and tricks
Custom macros
Nested macros
Future of macros
What is a macro?
• Macro in Kentico CMS:
– “Abstraction of the code that can be replaced by dynamic or context
specific value on-the-fly without compilation.”
• Reasons:
– Security – Limited set of data, read only
– Practical – Injecting dynamic values into plain text without coding
• Conclusion:
– “Each day, the macros prove that they are the right way to go”
– “Macros have future”
History of macros
• V 1.x
– Only ASPX templates, everything dynamic done via CodeBehind
– Only hardcoded macros in queries or e-mail templates
##WHERE##, {%useremail%}
• V 2.0
– Portal engine – How to dynamically populate web part parameters
without giving the user access to the code?
• V 2.3
– MacroResolver + first macro types
(localization, data & context, query string, cookie)
– Allowed parametrization of where conditions (text properties) from
query string or context e.g. “NewsID = {?newsid?}”
History of macros
• V 3.0
– Path & Custom macros, Path expressions
– Dynamic context-based paths, custom logic
• V 4.0
– Change to the UI
– Dynamic non-text properties
– Macro parameters
{?username|(equals)administrator?}, {?newsid|(toint)?}
• V 5.5
– Macro debug, more parameters
Macro types
• Data & Context – {%DocumentName%}
• QueryString – {?myvalue?}
• Localization – {$resourcekey$}
• In-place localization – {$=Hello|cs-cz=Ahoj$}
• Path – {&/{0}/Teaser&}
• Cookie – {@cookiename@}
• Custom – {#expression#}
Macro parameters
• Syntax – {%expression|(param1)value1|(param2)value2%}
• Modification or evaluation of the macro result
–
–
–
–
Ensuring type safety – {?newsid|(toint)?}
Boolean expressions – {%UserName|(equals)administrator%}
Mathematical functions – {%SKUPrice|(multiply)0.8%}
Processing flags – {%CurrentUser.FullName|(encode)true%}
Examples
• Dynamically populated texts
• Localization
• Controlling the visibility of a web part
• Where conditions based on query string
• Providing dynamic CSS styles (color profiles)
Custom macros
• {#expression#}
• Most powerful ones
• Your own code
• ~/App_Code/Global/CMS/CMSCustom.cs
public static string ResolveCustomMacro(sender, expression, out match)
{
// Your code
}
Nested macros
• Macros may be recursive (not query string, not cookies)
• Recursion is applied on the result
– {?name|(equals){%UserName%}?} – Not possible (yet)
– Request.QueryString[“name”] == “{%UserName%}”
• Same types of macros nested
– {%UserName|(equals)admin|(truevalue)Admin|(falsevalue){%FullName%}%}
– Is the end of the macro first %} or second?
• Paired
– {(1)%UserName|(equals)admin|(truevalue)Admin|(falsevalue){(2)%FullName%(2)}%(1)}
– The end has the same number as the start
Future of macros
• V 6.0 ??
– Unification
• {%QueryString.MyParam%}, {%Cookies.MyCookie%}, …
– Structured values (object hierarchy)
• {%CurrentDocument.Parent.Owner.FullName%}
– Collections
• {%CurrentDocument.Children[2].DocumentName%}
– C# like expressions in macros
• {% (UserName == “administrator”) && (QueryString.NewsID == 123) %}
• {% CurrentDocument.GetImage(“MyField”) %}
Summary
•
•
•
•
•
•
•
History of macros
Macro types
Macro parameters
Examples, tips and tricks
Custom macros
Nested macros
Future of macros
Sources of information
• Kentico CMS 5.5 Macro reference (poster)
• Developer’s guide
–
http://devnet.kentico.com/docs/devguide/index.html?appendix_a___macro_expressions.htm
• Blog
–
http://devnet.kentico.com/Blogs/Martin-Hejtmanek/June-2010/New-in-5-5--Macro-parameters.aspx
• E-mail
–
–
[email protected]
[email protected]