Copied to clipboard

Flag this post as spam?

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


  • Gonçalo Assunção 39 posts 68 karma points
    Feb 19, 2015 @ 13:04
    Gonçalo Assunção
    0

    Check if variable contains "currentPage"

    Hello guys,

    I'm trying to make a condition, where the code only runs if a variable contains the currentPage..
    I'm passing the $source page, to get all of its children...
    here's the code:

    <xsl:variable name="items" select="umbraco.library:GetXmlNodeById($source)/descendant::*  [@isDoc and string(umbracoNaviHide) != '1']"  />

    <xsl:if test="contains($items, $currentPage)">

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

          'do something'

        </xsl:for-each>

    </xsl:if>

    If I choose the first page that is contained in "$items", the code is triggered, but if I go to the 2nd or 3rd page in $items, the code is not triggered

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 19, 2015 @ 13:10
    Chriztian Steinmeier
    1

    Hi Gonçalo,

    That's because contains() works on a string, so there's some complicated stuff happening that I can explain if you, like - but: You just need to test like this instead:

    <xsl:if test="$items[@id = $currentPage/@id]">
       <!-- do stuff -->
    </xsl:test>
    

    Hope that helps,

    /Chriztian

  • Gonçalo Assunção 39 posts 68 karma points
    Feb 19, 2015 @ 13:26
    Gonçalo Assunção
    0

    Bingo! That worked!

    Thank you Chriztian!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies