Copied to clipboard

Flag this post as spam?

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


  • chris cameron 36 posts 56 karma points
    Jan 23, 2012 @ 22:19
    chris cameron
    0

    Changing classes dependant on url

    I have a product list which is filtered using tags by appending the filter tag to the url ie ?filter=Special

    I want to adjust the class in a list of <a> tags depending on the special type selected and specified in the url

    ie url?filter=special1 then class should be "special1" ir url?filter=special2 then class should be "special2"

    this is the code I am using, the bit i am missing I think is the correct test statement to check the current url for the specified value of the tag.

    <xsl:if test="SpecialCategory != 0">                         
                              <xsl:attribute name="class">
                                <xsl:text>Special</xsl:text>
                              </xsl:attribute>
                            </xsl:if>

  • chris cameron 36 posts 56 karma points
    Jan 23, 2012 @ 22:21
    chris cameron
    0

    I also tried the followin g but that did not seem to work either

    <xsl:attribute name="class">
                            <xsl:choose>
                              <xsl:when test="@nodesTagged = Special">
                                <xsl:value-of select="string('special')"  />
                              </xsl:when>
                              <xsl:otherwise>
                                <xsl:value-of select="string('@nodesTagged')"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </xsl:attribute>

  • Nigel Wilson 939 posts 2061 karma points
    Jan 24, 2012 @ 00:37
    Nigel Wilson
    0

    Hi Chris

    Good to see you active on the forums...... 

    You could do it this way

    <xsl:variable name="myVariable">
    <xsl:choose>
    <xsl:when test="string(umbraco.library:RequestQueryString('filter')) != ''">
    <xsl:value-of select="umbraco.library:RequestQueryString('filter')"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:text>mydefaultclass</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <a class="{$myVariable}">
    ...
    </a>

     

    Hope this helps :-)

    Cheers

    Nigel

  • chris cameron 36 posts 56 karma points
    Jan 24, 2012 @ 01:15
    chris cameron
    0

    Are you saying in this test statement i can check for the filter ie

    RequestQueryString('filter')) != 'Special1'"
  • chris cameron 36 posts 56 karma points
    Jan 24, 2012 @ 03:27
    chris cameron
    0

    Disregard the above that does not work. Applying your code works though and applies a class to every link however it does not loop through all the tags but applies the same class as the page it is on to all links. How do I get it to apply different classes to the different tag links.

    ie <a class="Specials" href="/mailer.aspx?numberPerPage=12&amp;filter=Specials">Specials</a>

    <a class="Specials1" href="/mailer.aspx?numberPerPage=12&amp;filter=Specials1">Specials1</a>

    <a class="Specials2" href="/mailer.aspx?numberPerPage=12&amp;filter=Specials2">Specials2</a>

    <a class="Specials3" href="/mailer.aspx?numberPerPage=12&amp;filter=Specials3">Specials3</a>

     

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jan 24, 2012 @ 07:06
    Jan Skovgaard
    0

    Hi Chris

    If you remove the ! from string(umbraco.library:RequestQuerystring('filter')) != 'Special1' and change it to string(umbraco.library:RequestQuerystring('filter')) = 'Special1' then class should be set to "Special1".

    But it will only be set as long as the filter parameter holds the value "Special1" - don't you need to have the different classes set in advance?

    /Jan

  • chris cameron 36 posts 56 karma points
    Jan 24, 2012 @ 08:25
    chris cameron
    0

    yes correct i would like the classes all set at the beginning depending on the tabs available.

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jan 24, 2012 @ 08:32
    Jan Skovgaard
    0

    Hi Chris

    What does your code for fetching the available tabs? How do you generate them?

    You could write out a class name when iterating through them where you add a class like <a href="#" class="special-{position()}">Link</a> - by doing this each tab gets a unique class, but I'm a bit unsure if it's enough to meet your demands if you need something more specific perhaps - the mentioned method is very generic as you can see :)

    /Jan

  • chris cameron 36 posts 56 karma points
    Jan 24, 2012 @ 08:53
    chris cameron
    0

    Jan, Here is the code that reads what special types from the tags on products are in the system, This generates a list of links like a tag cloud however the list does not have any class styles which I need it to have depending on what special type it is

     

    <p>Special Types</p>
              <xsl:variable name="commaListofcat">
                <xsl:for-each select="$productsAll/category">
                  <xsl:value-of select="concat(.,',')"/>
                </xsl:for-each>
              </xsl:variable>
              <!--<xsl:value-of select="$commaListofcat"/>-->

              <article class="clear martop20">
                <div class="curved10 brd4px tagCloudGeneric rel">
                  <a class="curved5 sortButton" href="/promotions-competitions/?numberPerPage={$numberPerPage}">Show All</a>
                  <p>
                   
                       
                      
                   
                    <xsl:for-each select="tagsLib:getAllTags()/tags/tag">

                      <xsl:if test="contains(Exslt.ExsltStrings:lowercase($commaListofcat),Exslt.ExsltStrings:lowercase(.))">

                        <xsl:variable name="SpecialsClass">
                          <xsl:choose>
                            <xsl:when test="string(umbraco.library:RequestQueryString('filter')) != ''">
                              <xsl:value-of select="umbraco.library:RequestQueryString('filter')"/>
                            </xsl:when>
                            <xsl:otherwise>
                              <xsl:text>mydefaultclass</xsl:text>
                            </xsl:otherwise>
                          </xsl:choose>
                        </xsl:variable>
                       
                       
                        <a class="{$SpecialsClass}">
                                             
                          <xsl:attribute name="href">
                            <xsl:value-of select="concat(umbraco.library:NiceUrl($currentPage/@id),'?numberPerPage=',$numberPerPage,'&amp;filter=',.)"/>
                          </xsl:attribute>

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Jan 28, 2012 @ 00:34
    Jan Skovgaard
    0

    Hi Chris

    Sorry for my late reply.

    Have you been able to figure this one out yet?

    In order to ensure that I get exactly what it is you're after could you perhaps try to just hardcode what you want the output to look like? I would rather be sure that I understand you 100% than just write in the wild :)

    /Jan

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies