Dilvid
Dilvid

Reputation: 35

Umbraco XSLT RenderTemplate Woes

Needing a little guidance with XSLT and Umbraco. Fairly new to XSLT but I think I understand the concepts. Right on one page I have two columns, each with their own separate pickable content. This is done via the standard content picker property (one for each column). The issue is that I need to be able to have two different templates on the page. So in essence the page navigated two which has the columns has to render two of it's child items in its own page.

I have this working with one column using a generic XSLT which I found that basically just renders what ever child item it finds, but I want it to render what ever one the user picked.

I know the Content Picker returns the XML Node ID of the page and that can be used with the Render Template function to display it (I have an example of that), but when it comes to adding in my own properties and then passing them to the RenderTemplate function I get lost. New to this XSLT :).

So far I have...

<?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
       <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"
     xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
     xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
     xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
     xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
     xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
     xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets">
   <xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="nodeID" select="data[@alias='leftColumn']"/>
<xsl:template match="/">
      <xsl:value-of select="umbraco.library:RenderTemplate($nodeID)" disable-output-escaping="yes"/>
</xsl:template>

</xsl:stylesheet>

Any one know why this doesn't work and how to do what I'm after? The above gives a value was either too large or too small error.

Upvotes: 1

Views: 1120

Answers (1)

Goran Mottram
Goran Mottram

Reputation: 6304

You actually have two problems here ...

Calling RenderTemplate()

RenderTemplate actually requires two arguments when using an alternative template, the first being the content node ID, and the second being the chosen template you want applied.

<xsl:value-of 
    select="umbraco.library:RenderTemplate($nodeID, $templateID)" 
    disable-output-escaping="yes" />

See the following link for more information : http://our.umbraco.org/wiki/reference/umbracolibrary/rendertemplate

Too large or too small error

This one is simple to fix by putting an if-empty statement around the the code in question.

<xsl:if test="$nodeID != ''">
    <xsl:value-of 
        select="umbraco.library:RenderTemplate($nodeID, $templateID)" 
        disable-output-escaping="yes" />
</xsl:if>

The XSLT parser likes to assume certain values are null, when in reality they aren't. Another way to get by this is to check the Skip Errors checkbox when saving, but this makes debugging actual erroneous code a bit of a pain.

Hope it helps.

Upvotes: 1

Related Questions