Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nick 42 posts 216 karma points
    Aug 17, 2014 @ 14:54
    Nick
    0

    Creating reusable content

    Hi,

     

    I am using this fantastic piece of code http://our.umbraco.org/wiki/how-tos/creating-reusable-content to create small nuggest of resuable conte across my website, in most part it works fine.

    What I want to do for each piece of content is bring in the node name within a h4 TAG as well as the content, this is my markup, I can't seem to bring back this variable within the XSLT, could anybody help me with this?

    Kind regards

    <xsl:template name="Render">
     
    <xsl:param name="currentId" />

        <xsl:if test="string($currentId) != ''">
            <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById($currentId)" />
            <xsl:variable name="currentContent" select="$currentNode/moduleContent" />
                <xsl:element name="div">
                    <xsl:attribute name="class">panel</xsl:attribute>
                    <h4><xsl:value-of select="@nodeName"/></h4>
                    <p><xsl:value-of select="$currentContent" disable-output-escaping="yes" /></p>
                </xsl:element>
        </xsl:if>

    </xsl:template>

  • John C Scott 440 posts 1076 karma points
    Aug 18, 2014 @ 12:59
    John C Scott
    0

    Where you have

    <h4><xsl:value-of select="@nodeName"/></h4>

    you need to prefix that with the variable this @nodeName is coming from

    So for example if it were the default to show the current page there is the standard variable always available that you would use 

    <h4><xsl:value-of select="$currentPage/@nodeName"/></h4>
    However in the sample code you have above there is a variable created in the template that has the node specified by the $currentId which is passed through and assigned to the $currentNode variable so you could either do the same has been added to have a variable for current content 

    <xsl:variable name="currentContent" select="$currentNode/moduleContent" />

    where presumably moduleContent is the name of a document property that you have

    so the equivalent would be to add beneath this variable 

    <xsl:variable name="currentHeading" select="$currentNode/@nodeName" />

    and then 

    <h4><xsl:value-of select="$currentHeading"/></h4>
    or much simpler you don't really need to do this you can place that select directly in your H4 tag
    so it would be 
    <h4><xsl:value-of select="$currentNode/@nodeName"/></h4>

    I haven't tested this but I think this should work for you

    For clarity I've listed here then what the whole file might look like in two examples one where you assign the extra variable and one where you just use the selectors directly

    With extra variable:

            <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById($currentId)" />
            <xsl:variable name="currentContent" select="$currentNode/moduleContent" />
    <xsl:variable name="currentHeading" select="$currentNode/@nodeName" />
                <xsl:element name="div">
                    <xsl:attribute name="class">panel</xsl:attribute>
                    <h4><xsl:value-of select="$currentHeading"/></h4>
                    <p><xsl:value-of select="$currentContent" disable-output-escaping="yes" /></p>
                </xsl:element>

    Or just using the selector directly:

            <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById($currentId)" />
                <xsl:element name="div">
                    <xsl:attribute name="class">panel</xsl:attribute>
                    <h4><xsl:value-of select="$currentNode/@nodeName"/></h4>
                    <p><xsl:value-of select="$currentNode/moduleContent" disable-output-escaping="yes" /></p>
                </xsl:element>

     

    HTH :)

  • Nick 42 posts 216 karma points
    Aug 19, 2014 @ 17:07
    Nick
    0

    Hi John,

     

    Thanks very much for the advice, seems so simple when you know how. Works great thank you again.

    Cheers

    Nick

  • John C Scott 440 posts 1076 karma points
    Aug 19, 2014 @ 17:09
    John C Scott
    100

    you're very very welcome :)

    please remember to mark the solution (tick the green arrow)

    and hope you have many many happy fun filled hours with Umbraco 

    (it is very very good!)

Please Sign in or register to post replies

Write your reply to:

Draft