Copied to clipboard

Flag this post as spam?

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


  • Dave 16 posts 36 karma points
    Jul 22, 2010 @ 20:43
    Dave
    0

    Using page parameters Recursively for a macro

    Is it possible to pass a macro the value of an umbraco:item from a template?

    Currently in my templates I have:

    <!-- determine the body class based on the selected scheme, or parent node scheme-->
    <body class="<umbraco:Item field="colorScheme" useIfEmpty="default" recursive="true" runat="server"></umbraco:Item>">

    This is working nicely, and provides the end result that I need.  However, I also have a macro:

    <umbraco:Macro randomImage="[#randomImage]" Alias="RandomBackground" runat="server"></umbraco:Macro>

    Rather than having the macro depend on the parameter [#randomImage] which is a media Node, I'd rather allow it to default to the parent recursively, much like the body class does above.

    I tried the following:

    <umbraco:Macro randomImage="<umbraco:Item field="randomImage" recursive="true" runat="server"></umbraco:Item>" Alias="RandomBackground" runat="server"></umbraco:Macro>

    Which results in the following output:

    <umbraco:Macro randomImage="1216" Alias="RandomBackground" runat="server"></umbraco:Macro>

    Returning the NodeId of the parent as expected, but the macro doesn't appear to run?

    Can this even be done this way, or is there a correct approach?

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jul 22, 2010 @ 21:11
    Stefan Kip
    0

    You can create the macro in code-behind and set properties from there.

    Explained in the following topic/post: http://our.umbraco.org/forum/developers/api-questions/5407-Macro-parameters-from-codebehind?p=0#comment19960

  • Josh Townson 67 posts 162 karma points
    Jul 23, 2010 @ 17:01
    Josh Townson
    0

    Hi Dave,

    you just need to know a little more about the bracket syntax (like [#randomImage]). See this page: http://our.umbraco.org/wiki/reference/templates/umbracomacro-element

    which will tell you to do this:

    <umbraco:Macro randomImage="[$randomImage]" Alias="RandomBackground" runat="server"></umbraco:Macro>

    Basically "$" instead of # in the bracket syntax makes the page variable recursive

    /Josh

  • Dave 16 posts 36 karma points
    Jul 23, 2010 @ 18:49
    Dave
    0

    Josh,

    Thanks! that's exactly what I needed.

    ~Cheers

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies