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:
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.
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.
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?
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
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
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
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
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)"/>
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
is working on a reply...