There is now a few simple extension methods for using in Views. You'll need to upgrade to use version 2.5 of the package which does not support Umbraco v4.x.
Here are a few examples of each of the extension methods where 'categories' is the alias of the Category Selection property.
1. Get all categories assigned to the current page.
@foreach(var category in CurrentPage.GetCategories("categories"))
{
<li>@category.Name</li>
}
2. Get child pages of the current page which have the category with ID 1 assigned.
@foreach(var page in CurrentPage.GetChildrenByCategory("categories", 1))
{
<li>@page.Name</li>
}
3. Get descendants of the current page which have category with ID 2 assigned.
@foreach(var page in CurrentPage.GetDescendantsByCategory("categories", 2))
{
<li>@page.Name</li>
}
4. Get decendants of current page which have category with ID 2 assigned and the document type of 'umbTextpage'.
@foreach(var page in CurrentPage.GetDescendantsByCategory("categories", 2, "umbTextpage"))
{
<li>@page.Name</li>
}
5. Get all decendants of a known page which have category with ID 1 assigned.
@foreach(var page in Umbraco.TypedContent(1050).GetDescendantsByCategory("categories", 1))
{
<li>@page.Name</li>
}
I hope this helps.
As always, feel free to suggest additional functionality or improvements.
Ok, sorry, it's my fault, my property alias is "category" and I didn't update the snippet. Anyway, I installed 2.5.0 as a whole new section is an overkill, a tree node in Settings is sufficient. Examples work fine, thanks for great package!
Umbraco 6 Razor Usage
How do we use the categorisation package in Umbraco 6 with razor views? Bearing in mind we use IPublishedContent, not Node.
Hi Mark,
There is now a few simple extension methods for using in Views. You'll need to upgrade to use version 2.5 of the package which does not support Umbraco v4.x.
Here are a few examples of each of the extension methods where 'categories' is the alias of the Category Selection property.
1. Get all categories assigned to the current page.
2. Get child pages of the current page which have the category with ID 1 assigned.
3. Get descendants of the current page which have category with ID 2 assigned.
4. Get decendants of current page which have category with ID 2 assigned and the document type of 'umbTextpage'.
5. Get all decendants of a known page which have category with ID 1 assigned.
I hope this helps.
As always, feel free to suggest additional functionality or improvements.
Thanks,
James
Hi James,
I've just installed v2.5.1, created a couple of categories and assigned them using Category Picker. None of the examples above seem to work.
Was something changed?
Ok, sorry, it's my fault, my property alias is "category" and I didn't update the snippet. Anyway, I installed 2.5.0 as a whole new section is an overkill, a tree node in Settings is sufficient. Examples work fine, thanks for great package!
is working on a reply...