I'm new to Umbraco, and I'm still wading through all the docs and tutorials. I have a site where there's a placeholder on the template where one of three controls can be displayed. I can set these up with macros ok, I'm wondering if there's a way to check a property of the page in the template, and load a macro based on the property.
e.g. I have three controls, latest news, contact details and latest events. I have a multiple select list for my documenttype where they can choose one or more of the controls, and I want a way of loading in the macros based on the selected values. I did see some mention of using the Nodefactory in the template, but I can't find the example, any help or pointers would be greatly appreciated!
it may be possible, although I've never tried it. Macro's (at least in v4) are nothing more than .NET server controls. You should be able create instances of the control at run time, set the appropriate properties and then it's "just work".
Dynamically include macro
Hi,
I'm new to Umbraco, and I'm still wading through all the docs and tutorials. I have a site where there's a placeholder on the template where one of three controls can be displayed. I can set these up with macros ok, I'm wondering if there's a way to check a property of the page in the template, and load a macro based on the property.
e.g. I have three controls, latest news, contact details and latest events. I have a multiple select list for my documenttype where they can choose one or more of the controls, and I want a way of loading in the macros based on the selected values. I did see some mention of using the Nodefactory in the template, but I can't find the example, any help or pointers would be greatly appreciated!
it may be possible, although I've never tried it. Macro's (at least in v4) are nothing more than .NET server controls. You should be able create instances of the control at run time, set the appropriate properties and then it's "just work".
But as I said, I haven't tried it ;)
You could do it in inline code, with <% if %> blocks, and render different <umbraco:Macro /> tags.
Yes this is possible.
Here is my blog post detailing how it can be done.
The main thing to watch out for is inconsistent capitalisation of parameters and attributes of your macros.
T
Thanks Stephan and Tim for your replies, I've got it sorted now I think, thank you very much for your help!
:)
is working on a reply...