Copied to clipboard

Flag this post as spam?

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


  • Hundebol 167 posts 314 karma points
    Sep 10, 2013 @ 13:22
    Hundebol
    0

    Show related pages based on multiple tags

    Hi,

    I have a working solution where i can find related pages based on a tag . 

    The tag could be "candy", like this: http://localhost:28192/en/tag?filterby=candy

    Then this XSLT kicks in

    <xsl:if test="string-length($currentPage/tags) &gt; 0">
    
          <!-- SHOW TAGS INDIVIDUALY AND AS LINKS -->          
          <xsl:if test="string-length($currentPage/tags) > 0">  
            <div class="tags"><p>Tags: 
            <xsl:variable name="items" select="umbraco.library:Split($currentPage/tags,',')" />    
              <xsl:for-each select="$items//value">
              <a href="/tag?filterby={current()}">      
                <xsl:value-of select="current()"/>
              </a>
            </xsl:for-each>    
                </p> 
            </div>
          </xsl:if> 
    
    </xsl:if>
    

     

    But, is it maybe possible to tweak this so that i can find based based on multiple tags?

    Like "candy" and "cake", like this: http://localhost:28192/en/tag?filterby=candy,cake

    I've seen this done in Razor (http://daniel.streefkerkonline.com/tagging-and-umbraco/), but I would like to keep this in XSLT

    Any help appreciated.

    best regards, Brian

  • Hundebol 167 posts 314 karma points
    Sep 13, 2013 @ 08:41
    Hundebol
    0

    Anyone? :)

  • Kasper Dyrvig 246 posts 379 karma points
    Sep 17, 2013 @ 10:52
    Kasper Dyrvig
    0

    Not sure I understand the concept... Is it you click on a tag and see the corresponding pages. Then you click on another tag so you now search for pages maching both (or just one?) of the selected tags?

  • Hundebol 167 posts 314 karma points
    Sep 17, 2013 @ 15:13
    Hundebol
    0

    It's actually not how to make the user select tags - it's how to make the XSLT show results for more tags.

    Right now i can only search for 1 tag, in this case "candy", by making this query: tag?filterby=candy

    I would like to show results for a search of multiple tags, in this case "candy" and "cake", which would be something like this query: tag?filterby=candy,cake (this is what he did in the razor: http://daniel.streefkerkonline.com/tagging-and-umbraco/))

    Example:

    Product 1, tagged with: candy
    Product 2, tagged with cake
    Product 3, tagged with candy & cake

    In 1 tag search i would like to be able to get all 3 products - which i can't at the moment. (I can get Product 1+3 with the candy-tag, or Product 2+3 with cake-tag)

  • Kasper Dyrvig 246 posts 379 karma points
    Sep 18, 2013 @ 16:01
    Kasper Dyrvig
    100

    Aha... I don't have a plug'n'play solution (don't have more time today). But maybe this concept can get you startet:

    <xsl:variable name="filterby" select="umbraco.library:RequestQueryString('filterby')"/>
    <xsl:for-each select="umbraco.library:Split($filterby, ',')/value">
    <xsl:variable name="ct" select="."/>
    <xsl:for-each select="$currentPage/* [@isDoc and umbracoNaviHide != 1]">
    <xsl:if test="contains(tags, $ct)">
    <p><xsl:value-of select="@nodeName"/> (<xsl:value-of select="travelTags"/>)</p>
    </xsl:if>
    </xsl:for-each>
    <br />
    </xsl:for-each>
  • Hundebol 167 posts 314 karma points
    Oct 01, 2013 @ 16:06
    Hundebol
    0

    Hi Kasper,

    Thanks so much for your help - much appreciated and just what I needed to make it work. below my final and working code

    <!-- Query-string in the browser -->
    <xsl:variable name="filter" select="umbraco.library:RequestQueryString('filter')"/>
    <!-- run a for-each to split the tags -->  
    <xsl:for-each select="umbraco.library:Split($filter, ',')/value">
     
    <!-- Save the values in a variable --> <xsl:variable name="ct" select="."/>
    <!-- Run a for-each to over the nodes we want to "search" --> <!-- We will look for pages underneath node id 1061 - change this to fit your hierachy --> <xsl:for-each select="umbraco.library:GetXmlNodeById(1061)/descendant-or-self::*">
    <!-- Check if our variable is not empty --> <xsl:if test="$ct != ''"> <!-- Check to if any of these pages contains the tags from our ct-variable --> <xsl:if test="contains(tags, $ct)">
    <!-- Product name --> <xsl:value-of select="nodeName" />
    </xsl:if> </xsl:if>
    </xsl:for-each>
    </xsl:for-each>

     

  • 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