Copied to clipboard

Flag this post as spam?

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


  • barry 1 post 21 karma points
    May 25, 2012 @ 12:54
    barry
    0

    get content from parent page

    I'm trying to create a carousel that will be displayed on multiple pages. I have added objects of type 'carouselitem', which have an image and a caption properties, under the homepage and I can select them using the xslt below:

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="documentTypeAlias" select="string('CarouselItem')"/>

    <xsl:template match="/">

    <div id="wwhomepagecarousel">
      <xsl:for-each select="$currentPage/*[name() = $documentTypeAlias]">
         <div class="carousel">
           <div class="carouselcaption"><p><xsl:value-of select="caption" disable-output-escaping="yes" /></p></div>
           <img class="carouselimage" width="500px" height="334" src="{umbraco.library:GetMedia(image,0)/umbracoFile}"/>
        </div>
     
      </xsl:for-each>
    </div>
    </xsl:template>


    This xslt is called in the master file, and it works fine for the homepage which has the carouselitem objects under it. However I need to create more pages under the homepage which will use the same master file and display the same carousel content.

    When I add a new page it does not display the items in the carousel. I presume I need to select the parent node and then the items? I have tried this:

    <xsl:for-each select="$currentPage/parent::node/*[name() = $documentTypeAlias]">


    But it did not work.

    Any suggestions?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 27, 2012 @ 01:42
    Chriztian Steinmeier
    0

    Hi Barry,

    Since your homepage contains the CarouselItem, this is accomplished simply by finding the root node first, and using that as the "base":

    <xsl:param name="currentPage" />
    <!-- Find the Home page here - usually at level 1 -->
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <xsl:variable name="documentTypeAlias" select="'CarouselItem'" />
    
    <xsl:template match="/">
        <div id="wwhomepagecarousel">
     <xsl:for-each select="$siteRoot/*[name() = $documentTypeAlias]">
                <div class="carousel">
                    <div class="carouselcaption">
                        <p>
                            <xsl:value-of select="caption" disable-output-escaping="yes" />
                        </p>
                    </div>
                    <img class="carouselimage" width="500px" height="334" src="{umbraco.library:GetMedia(image, 0)/umbracoFile}" />
                </div>
            </xsl:for-each>
        </div>
    </xsl:template>

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft