x First time here? Check out the FAQ


    (Copied from en.wikibooks.org/.../RenderMacroContent)



    Run a macro and insert the output into your XSLT.


    RenderMacroContent(String Text, Int32 PageId)

    Text: an encoded version of the template 'macro' code (see below for proper encoding)

    PageId: NodeID for the node you want to use for the content for the macro

    String Text Encoding Instructions:

    When you are putting the code for your macro in a template it looks something like this:

    <?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>

    To encode this for the RenderMacroContent function follow these steps:

    1. Change '<' to '&lt;'

    &lt;?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3">&lt;/?UMBRACO_MACRO>

    2. Change '>' to '&gt;'

    &lt;?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"&gt;&lt;/?UMBRACO_MACRO&gt;

    3. Change '"' to '&quot;'

    &lt;?UMBRACO_MACRO macroAlias=&quot;LatestNews&quot; numberOfItems=&quot;3&quot;&gt;&lt;/?UMBRACO_MACRO&gt;

    4. When you put this into the XSLT, enclose the whole thing in single quotes:

    umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;LatestNews&quot; numberOfItems=&quot;3&quot;&gt;&lt;/?UMBRACO_MACRO&gt;'...

    Example XSLT Usage:

    <xsl:value-of select="umbraco.library:RenderMacroContent('<?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>', @id)" disable-output-escaping="yes"/>

    Little Bonus: XSLT to do the encoding for you

    If you want to be able to just "cut & paste" the standard template macro code into your XSLT and have it encoded properly, add this bit of code to a new XSLT:

    <xsl:variable name="Macro"> <xsl:value-of select="{PUT YOUR TEMPLATE MACRO CODE HERE}"/> </xsl:variable> <xsl:variable name="MacroEncoded"> <xsl:value-of select="umbraco.library:Replace(umbraco.library:Replace(umbraco.library:Replace($Macro, '"', '&quot;'), '>', '&gt;'), '<', '&lt;')"/> </xsl:variable>

    Then use this to render the encoded XSLT to a test page in your browser (which you can then cut & paste into your XSLT code):

    <xsl:value-of select="$MacroEncoded" />


    Version 4 Warning

    Warning, Umbraco 4 macros with new templates have a different syntax however the XSLT extention still requires the old v3 one so if you copy the macro inserted into a v 4 template you need to change it to v3


    <umbraco:Macro Alias="Name" runat="server"></umbraco:Macro>


    <?UMBRACO_MACRO macroAlias="Name" runat="server"></?UMBRACO_MACRO>

    (with escaping)