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 *@
{
<li>
<a href="/articles/tags/@Server.UrlEncode(item.TagCaption)" class="level@(current)"> @* I added the number to the class so I could differentiate styling *@
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
tagsLib:getAllTagsInGroup
But a razor version
Many thanks.
There are a number of methods in the Tag class you can use:
eg. umbraco.cms.businesslogic.Tags.Tag.GetTags()
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 " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:tagsLib="urn:tagsLib"
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">
<a href="{umbraco.library:NiceUrl($blogRoot)}?tag={current()}">
<xsl:choose>
<xsl:when test="@nodesTagged >10"><xsl:attribute name="class">large</xsl:attribute></xsl:when>
<xsl:when test="@nodesTagged >5"><xsl:attribute name="class">medium</xsl:attribute></xsl:when>
</xsl:choose>
<span><xsl:value-of select="current()"/></span>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Is there no way then?
Hi Stephen,
Maybe is something like this you are looking for. http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors/Tags
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.
/Dennis
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 *@
{
<li>
<a href="/articles/tags/@Server.UrlEncode(item.TagCaption)" class="level@(current)"> @* I added the number to the class so I could differentiate styling *@
@item.TagCaption @* Write out tag *@
</a>
</li>
}
}
I am not sure how to format it as code, sorry
For anyone (else) that lands here. I think this is the v7 modern way (where Supplier is your tag group name).
Then just foreach on them with
Saving me from going insane three years after post was submitted!! Thank you Steve :D
Just wanna say thanks Steve. I had some trouble with this, and it turns out to be this simple. Thanks alot!
is working on a reply...