Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Umbraco/Reference/umbraco.library/RenderMacroContent

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

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: 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"/> This string should of course be encoded, so it would look like this: <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;LatestNews&quot; numberOfItems=&quot;3&quot;&gt;&lt;/?UMBRACO_MACRO&gt;', @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 extension 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 (with escaping)