Written by
Ismail Mayat
For umbraco versions:
AllXSLT Example
How to reuse existing content
Here is a quick and handy way to address the issue of content re use. For example you have a content page already in one section of your web site namely About us. You also want this content to appear in another section without having to do a cut and paste and also maintain link between the master in About us so that you do not have to update in two places.
- Create an xslt macro call it ReuseContent
- Paste the following content into the macro <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library"> <xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="pageId" select="/macro/pageId"/>
<xsl:variable name="templateId" select="/macro/templateId"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:value-of select="umbraco.library:RenderTemplate($pageId, $templateId)" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
- Create the 2 parameters for the macro namely pageId which will be of type Content Picker and templateId which will be number. Check in macro property Use in editor check box.
- Create a new template call it Reuse content. Do not inherit from any other template. Also in this template only insert fields from document type that you want to display. If you do inherit from a master template that has global elements then you will get these global elements like header and footer appearing twice.
- Create a page that will be holder for content re use. Insert macro onto the page select using the macro content picker the content page you wish to re use in the template id field enter the id of the template created in step 4.
- Save and publish page
There is one limitation to this method. If the source page being re used already has a macro inserted into the content then re using page will not render properly this is due to escaping of the macro tag.