Macros in action Martin Hejtmanek CTO Kentico software

  • Slides: 13
Download presentation
Macros in action Martin Hejtmanek CTO, Kentico software s. r. o.

Macros in action Martin Hejtmanek CTO, Kentico software s. r. o.

Agenda • • History of macros Macro types Macro parameters Examples, tips and tricks

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

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

History of macros • V 1. x – Only ASPX templates, everything dynamic done via Code. Behind – 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 – Macro. Resolver + first macro types (localization, data & context, query string, cookie) – Allowed parametrization of where conditions (text properties) from query string or context e. g. “News. ID = {? newsid? }”

History of macros • V 3. 0 – Path & Custom macros, Path expressions

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 – {%Document. Name%} • Query. String – {?

Macro types • Data & Context – {%Document. Name%} • Query. String – {? myvalue? } • Localization – {$resourcekey$} • In-place localization – {$=Hello|cs-cz=Ahoj$} • Path – {&/{0}/Teaser&} • Cookie – {@cookiename@} • Custom – {#expression#}

Macro parameters • Syntax – {%expression|(param 1)value 1|(param 2)value 2%} • Modification or evaluation

Macro parameters • Syntax – {%expression|(param 1)value 1|(param 2)value 2%} • Modification or evaluation of the macro result – – Ensuring type safety – {? newsid|(toint)? } Boolean expressions – {%User. Name|(equals)administrator%} Mathematical functions – {%SKUPrice|(multiply)0. 8%} Processing flags – {%Current. User. Full. Name|(encode)true%}

Examples • Dynamically populated texts • Localization • Controlling the visibility of a web

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/CMSCustom.

Custom macros • {#expression#} • Most powerful ones • Your own code • ~/App_Code/Global/CMSCustom. cs public static string Resolve. Custom. Macro(sender, expression, out match) { // Your code }

Nested macros • Macros may be recursive (not query string, not cookies) • Recursion

Nested macros • Macros may be recursive (not query string, not cookies) • Recursion is applied on the result – {? name|(equals){%User. Name%}? } – Not possible (yet) – Request. Query. String[“name”] == “{%User. Name%}” • Same types of macros nested – {%User. Name|(equals)admin|(truevalue)Admin|(falsevalue){%Full. Name%}%} – Is the end of the macro first %} or second? • Paired – {(1)%User. Name|(equals)admin|(truevalue)Admin|(falsevalue){(2)%Full. Name%(2)}%(1)} – The end has the same number as the start

Future of macros • V 6. 0 ? ? – Unification • {%Query. String.

Future of macros • V 6. 0 ? ? – Unification • {%Query. String. My. Param%}, {%Cookies. My. Cookie%}, … – Structured values (object hierarchy) • {%Current. Document. Parent. Owner. Full. Name%} – Collections • {%Current. Document. Children[2]. Document. Name%} – C# like expressions in macros • {% (User. Name == “administrator”) && (Query. String. News. ID == 123) %} • {% Current. Document. Get. Image(“My. Field”) %}

Summary • • History of macros Macro types Macro parameters Examples, tips and tricks

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

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 – support@kentico. com – martinh@kentico. com