Copied to clipboard

Flag this post as spam?

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


  • Johan Roug 97 posts 153 karma points
    Sep 03, 2009 @ 21:56
    Johan Roug
    0

    using xslt to display campaigns

    I have the following tree

    • content
    • Kampagner
    • campaign01
    • campaign02

    each campaign in this folder have 3 fields (alias names: campaignHeader, campaignText, campaignImage)

    on a normal page which is on the same level as "Kampagner", I use the ultimate picker to display all campaigns.The alias name is "campaignss" THe editor can then choose via checkboxes what campaigns should be shown on the page. Or this is the way I want it to function

    can anyone help me out? I have tried a lot, and I can make the ID show, sometimes the content.. but I am getting blind on the code

    I use something like

    <xsl:variable name="pageCamp" select="$currentPage/data [@alias = 'campaigns']"/>

    <xsl:for-each select="$pageCamp">

               <xsl:if test="$currentPage/data [@alias = 'campaigns'] ">

                          <h2>

                               <xsl:value-of select="$pageCamp"/>

                          </h2>

                          <p>

                                     <xsl:value-of select="$currentPage/ancestor-or-self::node [@level = '1']/following::node/data [@alias = 'campaignHeader']"/>

                          </p>

               </xsl:if>

    </xsl:for-each>

  • dandrayne 1138 posts 2262 karma points
    Sep 04, 2009 @ 12:07
    dandrayne
    1

    If you're using the ultimate pick in the alias of "campaigns", the way to get it out as a list of ids is as follows

    <xsl:variable name="campaigns" select="$currentPage/data[@alias='campaigns']"/>
    <xsl:variable name="splitCampaigns" select="umbraco.library:Split($campaigns, ',')" />
    <xsl:for-each select="$splitCampaigns/value">

    <!-- now each current() of the loop is an id, and you can use the following to get the full current node -->
    <xsl:value-of select="umbraco.library:GetXmlNodeById(.)" />

    </xsl:for-each>

    It's stored as a comma separated list so you need to use split to get the individual ids.  From there you can get the rest of the data for the node relating to that id.  The code above is untested, but hopefully its a step in the right direction

    Dan

     

     

  • Johan Roug 97 posts 153 karma points
    Sep 04, 2009 @ 19:26
    Johan Roug
    0

    yeah it works. I get all the fields, and I only get the ones I have chosen on a specific page, so that is perfect, however I want it like this

    <xsl:for-each>

    <h2>alias='campaignHeader'</h2>

    <p>alias='campaignHeader'</p>

    </xsl:for-each>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 04, 2009 @ 19:43
    Dirk De Grave
    1

    Jonasrt,

    Dan has shown you how to get the node associated with the id stored in the 'campaigns' property, now it's up to you to display the fields for each specific campaign as an exercise...

    Oh, what the heck, here it is...

     

    <xsl:for-each select="$splitCampaigns/value">
      <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)"/>
      <h2><xsl:value-of select="$currentNode/data [@alias = 'campaignHeader']"/></h2>
      <p><xsl:value-of select="$currentNode/data [@alias = 'campaignHeader']"/></p>
    </xsl:for-each>

     

    Hope this helps.

     

    Regards,

    /Dirk

  • Johan Roug 97 posts 153 karma points
    Sep 04, 2009 @ 19:52
    Johan Roug
    0

    thank you

    It's quite difficult this xPath. XSLT is to some degree easy. I was using . instead of $currentNode, but for some reason, this did not render anything

  • Johan Roug 97 posts 153 karma points
    Sep 05, 2009 @ 01:29
    Johan Roug
    0

    for anyone interested, I have finnished the code with the help from you guys.

    What this code does is look at a page. If the page has any campaigns selected which are all created elsewhere in the treestructure, the campaigns are rendered. However if the current page is the home page, one kind of layout is used, if it on the other hand is a text page, another way of rendering the campaign is chosen.

      <xsl:variable name="campaigns" select="$currentPage/data[@alias='campaigns']"/>
    <xsl:variable name="splitCampaigns" select="umbraco.library:Split($campaigns, ',')" />

    <xsl:for-each select="$splitCampaigns/value">
    <xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById(.)"/>
    <xsl:choose>
    <xsl:when test="$currentPage[@nodeTypeAlias = 'Home']">
    <h2>
    <xsl:value-of select="$currentNode/data [@alias = 'campaignHeader']"/>
    </h2>
    <p>
    <xsl:value-of select="$currentNode/data [@alias = 'campaignText']"/>
    </p>
    </xsl:when>
    <xsl:otherwise>
    <div class="sideColumn">
    <h2>
    <xsl:value-of select="$currentNode/data [@alias = 'campaignHeader']"/>
    </h2>
    <p>
    <xsl:value-of select="$currentNode/data [@alias = 'campaignText']"/>
    </p>
    </div>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
Please Sign in or register to post replies

Write your reply to:

Draft