Umbraco/Reference/umbraco.library/RenderMacroContent
Purpose:
editRun a macro and insert the output into your XSLT.
Arguments:
editRenderMacroContent(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:
editWhen 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 '<'
- <?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>
2. Change '>' to '>'
- <?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>
3. Change '"' to '"'
- <?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>
4. When you put this into the XSLT, enclose the whole thing in single quotes:
- umbraco.library:RenderMacroContent('<?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>'...
Example XSLT Usage:
edit<xsl:value-of select="umbraco.library:RenderMacroContent('<?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"></?UMBRACO_MACRO>', @id)" disable-output-escaping="yes"/>
This string should of course be encoded, so it would look like this:
<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
editIf 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, '"', '"'), '>', '>'), '<', '<')"/> </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
editWarning, 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
i.e.
<umbraco:Macro Alias="Name" runat="server"></umbraco:Macro>
becomes
<?UMBRACO_MACRO macroAlias="Name" runat="server"></?UMBRACO_MACRO>
(with escaping)