Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    May 09, 2011 @ 20:56
    FarmFreshCode
    0

    XSLT - If Statement - To Show Content (or not)

    Hello Everyone,

    Im working on a simple little XSLT script to allow my editors to include (or not) a YouTube video panel on the page. By default I want it to be set to display the video section, but if my editor would like to hide it, they can simply "check off" the hide option in the admin and it will be removed for that page.

    Here's a screenshot:

    I created a True/False datatype (youTubeShow) and would like to have a statement like.

    If on the current page "youTubeShow" = 0, then display (html code here),
    else display nothing.

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 09, 2011 @ 21:03
    Jan Skovgaard
    2

    Hi FFC

    I suppose you should be able to fetch the content like...

     

    <xsl:if test="$currentPage/youTubeShow != '1'>

    <!-- your code goes here --->

    </xsl:if>

    Isn't this what you're after?

    By the way I think you should change the alias to youTubeHide since that is what this property should do, right? It's a bit confusing that it's named "Show" when it's supposed to hide stuff when it has been checked - just nitpicking I know...:-)

    /Jan

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 09, 2011 @ 21:09
    Matt Brailsford
    2

    Hey FFC,

    As Jan said really, althout I'd probably question whether you need the boolean at all. Why not just check whether there is a youtube video URL entered? If there is one, show the video, else don't. Should save you an extra click at least.

    <xsl:if test="string-length($currentPage/youTubeUrl) &gt; 0">
    <!-- insert video player code here -->
    </xsl:if>

    Cheers

    Matt

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 09, 2011 @ 21:13
    Jan Skovgaard
    0

    Do'h, off course! If the string is empty...no video is shown...should have caught that one myself :D

    /Jan

  • FarmFreshCode 225 posts 422 karma points
    May 09, 2011 @ 21:19
    FarmFreshCode
    0

    @Jan - Thanks. I think I was making it more complicated than it needed to be.. you answers works just fine. and your right about changing the name to Hide.. good call

    @Matt - this video section is going to be a recursive element, so in this case using a true/false value will work out better for me since a video is not really declared on each page. But thanks for the suggestion

     

Please Sign in or register to post replies

Write your reply to:

Draft