Copied to clipboard

Flag this post as spam?

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


  • Probocop 51 posts 71 karma points
    Jan 18, 2011 @ 11:27
    Probocop
    0

    Listing all content that contains a specified 'tag'?

    Hi, On the site I'm developling, I have a series of pages where the user can specify a Tag, and the page will display a list of content that contains that Tag. But I haven't managed to get the page displaying anything. Can anybody see anything wrong with the following XSLT?

    The list of items can be narrowed further by clicking a tag which is displayed on the page.

    'contentTags' is a field on all document types for entering the tags.

    'tagToDisplay' is the field on the current document type for specifying the tag in which to display the content for.

      <xsl:variable name="articles">
        <xsl:choose>
          <xsl:when test="umbraco.library:Request('tag')">
            <xsl:copy-of select="$currentPage/ancestor-or-self::* [@isDoc and string(umbracoNaviHide) != '1' and contains(contentTags,umbraco.library:Request('tag'))]" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:copy-of select="$currentPage/ancestor-or-self::* [@isDoc and string(umbracoNaviHide) != '1' and contains(contentTags,$currentPage/tagToDisplay)]" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    <xsl:for-each select="msxml:node-set($articles)/* [@isDoc]">
      Show the page heading
    </xsl:for-each>

    My content tree is as follows, and its the pages within the Policy section that I'm trying to list the content on.

    Thanks!

    Dave

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jan 18, 2011 @ 13:43
    Chriztian Steinmeier
    2

    Hi Dave,

    You're only querying the ancestor axis for nodes, try to set a homePage variable once, and select pages from its descendant axis in stead - something like this:

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    <xsl:variable name="tag" select="umbraco.library:Request('tag')" />
    
    <xsl:variable name="articles">
        <xsl:choose>
            <xsl:when test="$tag">
                <xsl:copy-of select="$siteRoot//*[@isDoc][not(umbracoNaviHide = 1)][contains(contentTags, $tag)]" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="$siteRoot//*[@isDoc][not(umbracoNaviHide = 1)][contains(contentTags, $currentPage/tagToDisplay)]" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    /Chriztian

  • Probocop 51 posts 71 karma points
    Jan 18, 2011 @ 13:50
    Probocop
    0

    Hi Chriztian

    That makes perfect sense, that you very much!

    Dave

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 07, 2011 @ 22:19
    bob baty-barr
    0

    what if tag is a comma separated list of tags?? how would that work in this scenario? i am assuming split and a loop with a call to a template??

Please Sign in or register to post replies

Write your reply to:

Draft