Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    May 07, 2013 @ 11:44
    Martin
    0

    MNTP - Group First 2 Nodes & Subsequent Nodes in Groups Of 3

    Sorry, this is a double post, but I had issues with the preformatted code in my replies making it hard to understand.

    http://our.umbraco.org/forum/developers/xslt/40446-XSLT-Group-Nodes-In-2-or-3

    Chriztian has been a great help, and did all the hard work.

    Im still having an issue with appling a class through the with-param on the first group. Ive never tried passing a class this way and was wondering how it works.

    Any help would be grateful. Thanks

     

    <xsl:param name="currentPage" />

    <!-- This is the number of initial items -->
    <xsl:variable name="offset" select="2" />

    <!-- This the number of nodes to group subsequently -->
    <xsl:variable name="groupSize" select="3" />

    <xsl:template match="/">

    <!-- Process the MNTP property -->
    <xsl:apply-templates select="$currentPage/homeFeatureBlock" />

    </xsl:template>

    <!-- Template for the MNTP property -->
    <xsl:template match="homeFeatureBlock">

    <!-- First group -->
    <div class="initial-row row clearfix">
    <xsl:apply-templates select="MultiNodePicker/nodeId[position() &lt;= $offset]" >
                 <xsl:with-param name="class" select="'eight columns block'" />   
            </xsl:apply-templates>
    </div>

    <!-- Subsequent groups -->
    <xsl:for-each select="MultiNodePicker/nodeId[((position() + $offset - 1) mod $groupSize) = 1]">
    <div class="grouped-row row clearfix">
    <xsl:apply-templates select=". | following-sibling::nodeId[position() &lt; $groupSize]" />
    </div>
    </xsl:for-each>
    </xsl:template>

    <!-- Helper to get the referenced node -->
    <xsl:template match="nodeId">
    <xsl:apply-templates select="id(.)" />
    </xsl:template>

    <!-- Generic template for a block -->
    <xsl:template match="*[@isDoc]">
            <xsl:param name="class" select="'one-third column block'" />
            <div class="{$class}">
    <xsl:variable name="image" select="blockImage[normalize-space()]"/>
    <xsl:choose>
    <xsl:when test="$image !=''">
    <xsl:apply-templates select="$image" />
    </xsl:when>
    <xsl:otherwise>
    <img src="/media/7832/defaultpixel.png"/>
    </xsl:otherwise>
    </xsl:choose>
    <h4><xsl:value-of select="@nodeName" /></h4>
    <p><xsl:value-of select="blockDescription" disable-output-escaping="yes"/></p>

    <!-- Output the URL using umbraco.library's NiceUrl method -->
    <a class="morelink" href="{umbraco.library:NiceUrl(@id)}">
    <xsl:text>more information</xsl:text>
    </a>


    </div>
    </xsl:template>

    <!-- Image for block -->
    <xsl:template match="Image">
    <img src="{umbracoFile}"  alt="{@nodeName}" />
    </xsl:template>

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 12, 2013 @ 11:56
    Chriztian Steinmeier
    0

    Hi Martin,

    Ooh - that's actually my bad - there's nothing magic about it; it works by sending along the parameter - but in the case of the nodeId template, I'm not passing the class parameter along to the rendering template - fix it by adding the parameter (so the template receives it), and then passing it along when applying:

    <!-- Helper to get the referenced node -->
    <xsl:template match="nodeId">
        <xsl:param name="class" />
        <xsl:apply-templates select="id(.)">
            <xsl:with-param name="class" select="$class" />
        </xsl:apply-templates>
    </xsl:template>

    Hope that helps :-)

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft