Copied to clipboard

Flag this post as spam?

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

  • Jacob Polden 67 posts 177 karma points
    Mar 12, 2012 @ 11:26
    Jacob Polden

    Listing Tags in Razor

    Hello, I am trying to create a list of all the tags used on my website. I'm looking for a simliar function to this which is in XSLT


    But a razor version

    Many thanks.

  • Dan Diplo 1553 posts 6176 karma points MVP 4x c-trib
    Mar 14, 2012 @ 14:51
    Dan Diplo

    There are a number of methods in the Tag class you can use:


    eg. umbraco.cms.businesslogic.Tags.Tag.GetTags()

  • Jacob Polden 67 posts 177 karma points
    Mar 15, 2012 @ 16:03
    Jacob Polden

    To give you some context I'm trying to write this XSLT macro in Razor. How would I apply this GetTags() method in my new script?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
      exclude-result-prefixes="msxml umbraco.library tagsLib">

    <xsl:output method="html" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:variable name="blogRoot" select="$currentPage/ancestor-or-self::BlogListing/@id"/>

    <xsl:template match="/">
    <ul class="add-nav">
      <xsl:for-each select="tagsLib:getAllTagsInGroup('blog')/tags/tag">
        <xsl:sort select="@nodesTagged" order="descending"/>
            <li class="cat-link">
                  <xsl:when test="@nodesTagged &gt;10"><xsl:attribute name="class">large</xsl:attribute></xsl:when>
                  <xsl:when test="@nodesTagged &gt;5"><xsl:attribute name="class">medium</xsl:attribute></xsl:when>
                <span><xsl:value-of select="current()"/></span>



  • Stephen Kiers 41 posts 62 karma points
    May 21, 2013 @ 22:56
    Stephen Kiers

    Is there no way then?

  • Dennis Aaen 4495 posts 18201 karma points admin hq c-trib
    May 21, 2013 @ 23:25
    Dennis Aaen

    Hi Stephen,

    Maybe is something like this you are looking for.

    I must mention that I am pretty new to Razor, and not yet been worked so much with the Razor syntax.

    I hope it can help you in some way.


  • Stephen Kiers 41 posts 62 karma points
    May 22, 2013 @ 00:21
    Stephen Kiers

    This is what I ended up doing


    var blogTags = umbraco.cms.businesslogic.Tags.Tag.GetTags("default").OrderByDescending(t => t.NodeCount); @* make all tags an enumerable *@

    var split = 10 / blogTags.First().NodeCount; @* If I want 10 levels, what is the breakpoints? *@


    @foreach (var item in blogTags)


    var current = Math.Round(item.NodeCount * split + 0.0); @* what is this tag's level *@

    if (current > 5) @* I only wanted to show ones greater than 5 in my sample *@



    <a href="/articles/tags/@Server.UrlEncode(item.TagCaption)" class="[email protected](current)"> @* I added the number to the class so I could differentiate styling *@

    @item.TagCaption @* Write out tag *@





  • Stephen Kiers 41 posts 62 karma points
    May 22, 2013 @ 00:30
    Stephen Kiers

    I am not sure how to format it as code, sorry

  • Steve Morgan 1304 posts 4355 karma points c-trib
    Jul 02, 2015 @ 15:13
    Steve Morgan

    For anyone (else) that lands here. I think this is the v7 modern way (where Supplier is your tag group name).

    var tags = Umbraco.TagQuery.GetAllTags("Supplier");

    Then just foreach on them with

    @foreach (var tag in tags)
                    <li data-filter="@(tag.Text)">@(tag.Text)</li>
  • Gary 80 posts 377 karma points
    Nov 29, 2018 @ 18:00

    Saving me from going insane three years after post was submitted!! Thank you Steve :D

  • Jesper Balslev 2 posts 72 karma points
    Mar 03, 2017 @ 10:51
    Jesper Balslev

    Just wanna say thanks Steve. I had some trouble with this, and it turns out to be this simple. Thanks alot!

Please Sign in or register to post replies

Write your reply to: