Copied to clipboard

Flag this post as spam?

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


  • umbracov 38 posts 58 karma points
    Mar 31, 2011 @ 18:49
    umbracov
    0

    If condition and bool property

    I have a property IsValid in Document  Type with type set to true/false. Now I want to check this value in my xslt and branch the functionality accordingly. How do I do this........my code always retruns false and does not branch out. I would appreciate if someone could provide me the code f/else condition.

    Here are some code samples that I found in the forums and have tried and  failed

    <xsl:if test="IsValid ">

    <xsl:if test="string(data [@alias=IsValid ]) = '1'">

    <xsl:if test="string($currentPage/data [@alias=IsValid ]) = '1'">


    Thanks.

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 31, 2011 @ 18:56
    Kim Andersen
    0

    Hi

    Try this small snippet:

    <xsl:if test="$currentPage/IsValid='1'">
    <!-- Here we can do something if the true/false is checked -->
    </xsl:if>

    /Kim A

  • umbracov 38 posts 58 karma points
    Mar 31, 2011 @ 19:02
    umbracov
    0

    It always returns true no mater check for '1' or '0'.

    Thanks.

  • umbracov 38 posts 58 karma points
    Mar 31, 2011 @ 19:11
    umbracov
    0

    It works

    <xsl:if test="not(isValid='1')"> 

      do your stuff here

    </xsl:if >

    If the value is checked then IsValid returns '1' else NULLis returned.

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 31, 2011 @ 20:37
    Kim Andersen
    2

    Hmm.... A true/false property should return either 0 or 1 if you have published the page. Are you checking this inside a loop of some kind? I'm asking because you are not having $currentPage in the code from your recent post.

    If you're inside a loop, it would also make sense that $currenPage/IsValid doesn't return 0 or 1.

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 31, 2011 @ 21:10
    Jan Skovgaard
    0

    Could you perhaps share the XML output with us? This behaviour sounds a bit odd to me as well.

    What version of Umbraco are you using?

    /Jan

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Mar 31, 2011 @ 22:13
    Chriztian Steinmeier
    1

    Hi,

    I always use the not(propertyName = 1) version - also when checking umbracoNaviHide. It safeguards against the case where the property doesn't even exist on a Document (whether because it hasn't got it, or because it hasn't been published since it got it). 

    Kim's point is important - that you need $currentPage if not inside a loop or matching template.

    /Chriztian 

  • umbracov 38 posts 58 karma points
    Mar 31, 2011 @ 23:00
    umbracov
    0

    My umbraco version 4.5.2

    The reason for why 0 was not displayed was because once a new property is created the content has to be published, which I did not do because I thought the checkbox was to remain unchecked and so I did not bother publishing it ......................my mistake.

    I am inside the loop and hence not $currentPage.

    Thanks for the so many quick responses. I did learn something new today..........Thanks......guys!

  • 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