Copied to clipboard

Flag this post as spam?

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


  • Graeme 19 posts 111 karma points
    Mar 24, 2014 @ 18:09
    Graeme
    0

    Get value from a drop down data type

    Hi 

    I'm very new to Umbraco, I'm working on a project in v4.5.2 using an XSLT macro I'd like to get the value of dropdown data type set by the user within the content section and use this as a class within the body tag.

    Currently I have this as the body tag on the master page template:

     <body class="<umbraco:Macro Alias='BodyTagWithDynamicClass' runat='server'></umbraco:Macro>">

    Now what I'm trying to get is the value of the drop down Ideally utilising  ancestor-or-self to allow inherting from parent pages if not set on child page. The drop down is called colourScheme.

    I've tested the body tag syntax by just having 

    <xsl:template match="/">

    <!-- start writing XSLT -->
      <xsl:if test="1=1">blue</xsl:if>

    </xsl:template>

    within the BodyTagWithDynamicClass xslt file and this renders fine, can't just get my head around how to get the value of the dropdown.

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2014 @ 18:27
    Jan Skovgaard
    0

    Hi Graeme

    If I understand your issue correctly what you need to do is this

    Since I don't know what the alias of your homepage document type is you must of course alter the higlighted part to match the correct alias.

    If you're in doubt about the xpath the XSLT wizard of Umbraco aka Chriztian Steinmeier has done a pretty nice xpath visualizer that shows what you're hitting when using different axes.

    Hope this helps.

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 24, 2014 @ 18:28
    Jan Skovgaard
    0

    Ok, don't know what went wrong there but my code did not make it into the above answer...

    should be

    I'm asuming you're homepage alias is "Hompage". If it's something else you need to alter it.

    /Jan

  • Graeme 19 posts 111 karma points
    Mar 25, 2014 @ 11:34
    Graeme
    0

    Hi Jan,

    Thanks for the response, unfortunatley I still can't see any example code.

    I've changed my requirements a touch, I've now decided to add the value of the dropdown directly to certain classes with jquery.

    Here's what I have so far:

    <!-- start writing XSLT -->  
      <xsl:variable name="dropdownValue" select="($currentPage/ancestor-or-self::*[@isDoc and colourScheme != '']/colourScheme)"/>
      
      <xsl:if test="$dropdownValue != ''"><script>$(function(){$('.header-content').addClass('<xsl:value-of select="$dropdownValue"/>');$('.nav-landing').addClass('<xsl:value-of select="$dropdownValue"/>');});</script></xsl:if>

    And using the macro on the master page to out the js. It's working my only problem being I need it to find the value of the first drop down, if it doesn't find it on that page it then 'bubbles up' through the parent pages until it finds the first one, this should then be set to the variable $dropdownValue. What it writing to the class is the final value. Any ideas what I'm missing?

    Thanks

     


  • Graeme 19 posts 111 karma points
    Mar 25, 2014 @ 11:46
    Graeme
    1

    I posted to quick managed to find a resolution just needed to add [1] to find the first one

    <xsl:variable name="dropdownValue" select="($currentPage/ancestor-or-self::*[@isDoc and colourScheme != ''][1]/colourScheme)"/>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 25, 2014 @ 11:53
    Jan Skovgaard
    100

    Hi Graeme

    That was almost what my code looked like.

    I prefer to keep it in a variable where I simply try to fetch the homepage node.

    <xsl:variable name="home" select="$currentPage/ancestor-or-self::Homepage" />
    <xsl:value-of select="$home/colourScheme />

    Fingers crossed it makes it this time! :)

    /Jan 

Please Sign in or register to post replies

Write your reply to:

Draft