Macro parameter chaining

Rating: 4.9 / 5 stars - 14 vote(s).



Let's assume we've got an umbraco document type with a property 'Title' (Alias = 'title') and that we will use that property as a parameter we'd like to pass to a user control via a macro, but we don't want the user to force to enter the title for each newly created document. And, if the user hasn't entered a title, we will provide a default title. Well, in that case, you could use some code logic the check whether the field is empty and if so, set a default title.

Good news for you... we don't need to write that additional piece of code as umbraco can take care of this for us through macro parameter chaining. Syntax for parameter chaining in this particular case would be:

 

   1:  <umbraco:Macro inputParameter="[#title], My default title" Alias="ChainedMacroParams" runat="server"></umbraco:Macro>

 

In above code snippet, umbraco will replace the title - if left empty by the user - with the string "My default title". And it can even be more interesting to chain even more parameters, such as:

 

   1:  <umbraco:Macro inputParameter="[#title], [$otherTitle], My default title" Alias="ChainedMacroParams" runat="server"></umbraco:Macro>

 

In above case, umbraco will look up the title on the current document, and if not found or no value has been specified, look up the value of a property with alias 'otherTitle' recursively, and if still no value found, revert to the "My default title" value.

Other 'special properties' also supported as macro parameters are:

[@request]: Request string
[%cookie]: Cookie value

Enjoy!