1 / 13

Macros in action

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:

Télécharger la présentation

Macros in action

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Agenda • History of macros • Macro types • Macro parameters • Examples, tips and tricks • Custom macros • Nested macros • Future of macros

  3. 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”

  4. 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?}”

  5. 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

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

  7. 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%}

  8. Examples • Dynamically populated texts • Localization • Controlling the visibility of a web part • Where conditions based on query string • Providing dynamic CSS styles (color profiles)

  9. 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 }

  10. 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

  11. 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”) %}

  12. Summary • History of macros • Macro types • Macro parameters • Examples, tips and tricks • Custom macros • Nested macros • Future of macros

  13. 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

More Related