Copied to clipboard

Flag this post as spam?

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


  • Jos Huybrighs 23 posts 55 karma points
    Mar 04, 2011 @ 22:02
    Jos Huybrighs
    0

    Pass a property of a node as macro parameter

    Hi,

    I have a C# usercontrol which I call through a macro in my template. The macro invocation requires a NodeID to be passed where in some cases the ID is a property of another node.

    So, sometimes the macro is as simple as:

    <umbraco:Macro Alias="ClubPresentationSlideShow" runat="server"
                   NodeID="1370" />
    

    But when the ID is a property of another node I don't know how to pass that. It ideally should be something like the following:

    <umbraco:Macro Alias="ClubPresentationSlideShow" runat="server"
                   NodeID="{umbraco.library:GetXmlNodeById($nodeId)/myNodeId}" />
    

    The above declaration for NodeID is off-course wrong, but what I would like to know is whether there is a syntax that actually accomplishes what I want. If possible without the help of XSLT.

    Any help is highly appreciated.

    Jos

     

     

     

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Mar 05, 2011 @ 19:35
    Tim
    0

    If the node id is a property of the page that the macro is on, then yes. Assuming you have a page that has a property that contains a nodeId, say "myNode" then the syntax would be something like:

    [#myNode]

    You can also pass in recursive values, see the wiki article here: http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters/advanced-macro-parameter-syntax

    Hope that helps!

    :)

  • Jos Huybrighs 23 posts 55 karma points
    Mar 08, 2011 @ 23:11
    Jos Huybrighs
    0

    Tim,

    Thanks for the response.

    I am aware of the [#property] syntax but in this particular case the node from which I would like to access a 'child' property is not the current page. The recursiion support in Umbraco doesn't help here either because as I understood recursion is always upwards in the tree.

    If recursion would work downwards then conceptually it still is not correct imho (and so is recursion upwards).I have this well-defined node of which the property that I would like to use is logically a child property. Why would I have to iterate the umbraco tree (who knows how many nodes are in there) when I clearly know where the property is located? If you look at it from a programming point of view it is against everything we have learned before and considered as being good programming behavior.

    Anyhow, if this is how it is then I will have to make a work-around.

    Jos

     

     

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Mar 14, 2011 @ 10:36
    Tim
    0

    Hi Jos,

    Sorry for not getting back to you sooner, I've been away on holiday!

    If you know the node, I suppose you could use a node picker to pass the node ID through and then pull the property out in your user control/macro. If you wanted to make it more dynamic, you could pass in the node id as one property and the property alias as another and then get the property out in your macro maybe?

Please Sign in or register to post replies

Write your reply to:

Draft