Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 09, 2009 @ 02:23
    Tim
    0

    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!

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Nov 09, 2009 @ 02:58
    Aaron Powell
    0

    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 ;)

  • Stephan Lonntorp 195 posts 212 karma points
    Nov 09, 2009 @ 07:42
    Stephan Lonntorp
    0

    You could do it in inline code, with <% if %> blocks, and render different <umbraco:Macro /> tags.

  • Tim 225 posts 690 karma points
    Nov 09, 2009 @ 07:44
    Tim
    1

    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

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 10, 2009 @ 14:15
    Tim
    0

    Thanks Stephan and Tim for your replies, I've got it sorted now I think, thank you very much for your help!

    :)

Please Sign in or register to post replies

Write your reply to:

Draft