Copied to clipboard

Flag this post as spam?

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


  • Maarten Boer 61 posts 82 karma points
    Feb 22, 2010 @ 21:32
    Maarten Boer
    0

    Is it possible to use if statement in templates

    Hi

    I'm using a checkbox in my documenttype. This checkbox represent a style setting for a DIV ...overflow: hidden of auto

    I want to use the value of this checkbox to create someting in my template like

    <div test style="overflow:hidden;">  when checked

    or

    <div test style="overflow:auto;"> 

    all depending on the value of the checkbox.

    Is this possible in the template or a macro and how ???

    Im fairly new to umbraco so any help is welcome..

     

    Maarten

     

  • Jukka-Pekka Keisala 90 posts 226 karma points
    Feb 22, 2010 @ 22:25
    Jukka-Pekka Keisala
    0

    I would use xslt or if xsl is not your cup of tea you can make it in asp.net codebehind <div runat="server" id="myDiv">.

    You can also do it in jquery by adding <input type="hidden" and put value there and when loading page checking the value and putting $("myDiv").css("overflow","hidden")

     

  • Maarten Boer 61 posts 82 karma points
    Feb 22, 2010 @ 22:39
    Maarten Boer
    0

    i guess im looking for a solution in xslt although it is new to me.

    This means writing a xslt script where i use an if statement. How do i pass the value of the checkbox into the script ??

    Maarten

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 22, 2010 @ 22:44
    Kim Andersen
    2

    Hi Maarten

    I would use XSLT to take care of this problem, and in most cases also use XSLT to render the content inside of the div.

    You could make a new XSLT-file (and macro) and insert something like this:

    <div id="test">
        <xsl:attribute name="style">
    <xsl:choose>
    <xsl:when test="$currentPage/data[@alias='yourAlias'] = '1'">overflow:hidden;</xsl:when>
    <xsl:otherwise>overflow:auto;</xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    </div>

    Well, actually I would make the styling in a seperate css-file, and then just have two different clases to apply to the div like this:

    <div id="test">
    <xsl:attribute name="class">
    <xsl:choose>
    <xsl:when test="$currentPage/data[@alias='yourAlias'] = '1'">hidden</xsl:when>
    <xsl:otherwise>notHidden</xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    </div>

    Hope you understand, otherwise say so, and we'll figure it out :)

    /Kim A

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Feb 22, 2010 @ 23:14
    Aaron Powell
    5

    You can do it with server script blocks:

    <% if(umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("my_property") == "0") { %>
    <div style="overflow:hidden">
    <% } else { %>
    <div style="overflow:auto">
    <% } %>
    <!-- my content goes here -->
    </div>
  • Maarten Boer 61 posts 82 karma points
    Feb 25, 2010 @ 12:48
    Maarten Boer
    0

    Hi Guy's

    Thanks for the response. Both options XSLT and ASP work fine.

    ASP Crossed my mind because that's a language i'm familiar with.

    But since i'm trying to learn XSLT, the first options is up and running on my site.

    I LOVE UMBRACO :)

     

    Maarten

  • Kim Andersen 1447 posts 2196 karma points MVP
    Feb 25, 2010 @ 18:57
    Kim Andersen
    0

    Glad that we could help Maarten.

    Please remember to mark an answer as the solution.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft