Copied to clipboard

Flag this post as spam?

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

  • AndyM 6 posts 26 karma points
    Nov 22, 2015 @ 12:04

    V4.6.1 Getting all nodes that contain a specific value in a keywords field


    We're still on umbraco 4.6.1 but hoping you can still help. I'm sure there's already information out there on how to do this but I'm having trouble finding it.

    I'm trying to create a XSLT file and macro that generates a menu of related pages on the right hand column of my site.

    Within my umbraco document types i've created two fields.

    Field 1: Unique Keyword (this give the page a unique name to add to Field 2 below)

    Field 2: Send to pages (I add the unique keywords of related pages to this field)

    Then I wanted to create an XSLT loop to list all the pages that contained the current pages unique keyword

    So for example... If the unique keyword of the current page is 'unicorn' The the XSLT returns any page that contains 'unicorn' in the send to pages field.

    I basically want to create a similar pages feature that inst restricted to the node hierarchy, collecting everything regardless of level.

    If anyone could point me in the right direction that would be really helpful

  • Chriztian Steinmeier 2732 posts 8341 karma points MVP 5x admin c-trib
    Nov 22, 2015 @ 14:54
    Chriztian Steinmeier

    Hi Andy,

    As is usually the case, there's more than one way to implement such a feature.
    Are you using the Unique Keyword for anything else (i.e., could you just use a page's ID in the Send to pages field)?

    Anyways—here's a simple macro to help you get started:

    <?xml version="1.0" encoding="utf-8" ?>
        <xsl:param name="currentPage" />
        <!-- Grab the "Home" node -->
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
        <xsl:template match="/">
            <!-- Grab all pages that have the current page's `uniqueKeyword` in their `sendToPages` property -->
            <xsl:variable name="relatedPages" select="$siteRoot//*[@isDoc][umb:Split(sendToPages, ' ')/value = $currentPage/uniqueKeyword]" />
            <section class="related">
                <xsl:apply-templates select="$relatedPages" />
        <!-- Template for a related page -->
        <xsl:template match="*[@isDoc]">
                <xsl:value-of select="@nodeName" />

    Please note a couple of things:

    • uniqueKeyword and sendToPages are the aliases of the properties you've created - you may need to change these (case-sensitive, etc.)
    • I'm assuming you're just using a space between the keywords in the sendToPages property - if you're using commas or another character, you need to change that in the call to the Split() function.

    Hope that helps,


  • AndyM 6 posts 26 karma points
    Nov 23, 2015 @ 10:59

    This is great thanks for your help. So currentPage is a predefined parameter similar to umbracoNaviHide? I could see it being declared everywhere but I couldnt see it being set.

    Thanks for your quick response!


  • Chriztian Steinmeier 2732 posts 8341 karma points MVP 5x admin c-trib
    Nov 23, 2015 @ 11:05
    Chriztian Steinmeier

    Hi Andy,

    Yes (and no :-)

    $currentPage is a special parameter that Umbraco supplies as context to a macro.

    umbracoNaviHide is only a convention - but all of the predefined XSLT "templates" that you can start new macros off of, assume that you've used that alias for the property that determines if a page should be hidden in navigations.


Please Sign in or register to post replies

Write your reply to: