Umbraco/Reference/umbraco.library/RenderMacroContent

Purpose:
Run a macro and insert the output into your XSLT.

Arguments:
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">

To encode this for the RenderMacroContent function follow these steps:

1. Change '<' to '&amp;lt;'
 * &amp;lt;?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3">&amp;lt;/?UMBRACO_MACRO>

2. Change '>' to '&amp;gt;'
 * &amp;lt;?UMBRACO_MACRO macroAlias="LatestNews" numberOfItems="3"&amp;gt;&amp;lt;/?UMBRACO_MACRO&amp;gt;

3. Change '"' to '&amp;quot;'
 * &amp;lt;?UMBRACO_MACRO macroAlias=&amp;quot;LatestNews&amp;quot; numberOfItems=&amp;quot;3&amp;quot;&amp;gt;&amp;lt;/?UMBRACO_MACRO&amp;gt;

4. When you put this into the XSLT, enclose the whole thing in single quotes:
 * umbraco.library:RenderMacroContent('&amp;lt;?UMBRACO_MACRO macroAlias=&amp;quot;LatestNews&amp;quot; numberOfItems=&amp;quot;3&amp;quot;&amp;gt;&amp;lt;/?UMBRACO_MACRO&amp;gt;'...

Example XSLT Usage:


This string should of course be encoded, so it would look like this:



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:

     

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):



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

i.e.



becomes

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

(with escaping)