Copied to clipboard

Flag this post as spam?

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


  • lucein 2 posts 20 karma points
    Jul 17, 2009 @ 00:05
    lucein
    0

    Nesting Macro

    Hello,

    I'm new to Umbraco and I and my other devleopers have been working through the learning curve for Umbraco.  One question that keeps coming up and I can't seem to find an answer for is:

    With Macro's can you nest macro?  So that you can create macros that complete then move on to run other macros easily.

    Any help or direction would be greatly appreciated.

    Thank you

    Lucein

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 17, 2009 @ 00:19
    Sebastiaan Janssen
    0

    With XSLT macro's you can actually do this, from within the XSLT you could call render macro. But it's not something that I would recommend.

    If you have special needs like this, it's also very easy to just delve into the API and do whatever you'd like to do programmatically in a .net user control.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 17, 2009 @ 01:05
    Lee Kelleher
    0

    Some advice about nesting macros.  Sebastiaan is right about rendering (nested) macros from an XSLT macro, here's how:

    <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;MyMacro&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes" />

    BUT you can only render other XSLT macros - you can NOT render .NET user-control macros.  This is due to where the XSLT is processed in the ASP.NET page life-cycle.  You can not "go back" after the Page_Load has executed (where most developers usually do their code-behind logic).

    If you need to dynamically pull in macros from a .NET user-control (or any .NET class/code/method), then you can easily do that via the API (as Sebastiaan mentions).

    String renderedMacro = umbraco.library.RenderMacroContent('<?UMBRACO_MACRO macroAlias="MyMacro"></?UMBRACO_MACRO>', nodeId);

    But if you find yourself relying on nested Macros, then you might want to re-think what you are trying to achieve. If it's pulling out data, then XSLT Extensions might be a better way to go?

Please Sign in or register to post replies

Write your reply to:

Draft