When I was working on a site, I had a document type that uses the Tag Property Editor. The Tags property editor allows you to add multiple tags to a node. The document type I was using it on was a blog article and tags are used to categories each blog post.
In the past, I have used Composers, Interfaces, Controllers and RelationTypes to make a dropdown menu for unique categories but this is when I have a used a content picker. The issue I had with using the Tag Property type is there is no unique id associated to the tag. It's just a string of text.
I tried a number of different ways to get the RelationType to work but thankfully, my google skills came up with a great bit of documentation.
What I needed to do was make a new unique Data Type using the Property editor Tags, give it a unique Tag Group name.
Once this is created, I can then use it on a Document Type.
Now, this is the clever part.
There is an Umbraco Helper which you can use to query all your content by the Tag Group. The documentation shows a couple of examples.
I used it like so:
@{
var allTags = Umbraco.TagQuery.GetAllTags("noticeboardTags");
}
<select id="NoticeCategory">
<option value="">Category</option>
@{
foreach (var tag in allTags)
{
<option value="@tag.Text">@tag.Text</option>
}
}
</select>
No need for any crazy coding, just use the TaqQuery to get all the tags.
This pulls all tags used and outputs them in to a dropdown menu and it's really quick.
I hope it helps someone.
Published on: 22 September 2020