Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Mar 23, 2010 @ 13:41
    Dan
    0

    Cleanest way to get simple document type value on page

    Hi,

    On one of my document types I'm letting the user select a theme colour.  This is done by having a colorPicker datatype with the alias 'primaryColour' on the document type.  I've created a macro to embed a bit of CSS into the head of any page which has a value set for 'primaryColour'.  This must be a really silly question, but I just want to grab the value of 'primaryColour' in the macro - can I do it without a 'for-each' loop in there?  I was hoping to do something like this, but it doesn't seem to return a value when there is one:

    <xsl:template match="/">

    <xsl:variable name="primaryColour" select="$currentPage/node [string(data[@alias='primaryColour'])]"/>
    <!--
    I've also tried:
    <xsl:variable name="primaryColour" select="string(data[@alias='primaryColour'])"/>
    -->

    <xsl:if test="$primaryColour != ''">
    <style type="text/css">
    h1 {
    color: #<xsl:value-of select="$primaryColour"/>
    }
    </style>
    </xsl:if>
    </xsl:template>

    Thanks all

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 23, 2010 @ 13:44
    Jan Skovgaard
    0

    Hi Dan

    Which datatype have you selected to handle the color selection?

    I think you should be using the $currentPage parameter solution. If you have been using the dropdown list you'll get the name for the selected color.

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 23, 2010 @ 13:45
    Jan Skovgaard
    1

    Forgot to mention that I think you should write this

    <xsl:variable name="primaryColour" select="$currentPage/data [@alias = 'primaryColour']" /> since I guess you'll need the value from the current page, right?

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 23, 2010 @ 13:49
    Dirk De Grave
    2

    Hi Dan,

    Me thinks it should be:

    <xsl:variable name="primaryColour" select="string($currentPage/data[@alias='primaryColour'])"/>

     

    Cheers,

    /Dirk

     

     

     

     

     

     

     

  • Dan 1288 posts 3921 karma points c-trib
    Mar 23, 2010 @ 13:55
    Dan
    0

    Bingo, thanks Jan - it was the /node which needed to be /data.

Please Sign in or register to post replies

Write your reply to:

Draft