Accessing Classifications within Views
Hi,
Prior to Feather we would be able to access classifications applied to a module by using a Hierarchical/FlatTaxon tag built into Sitefinity to list out the associated classifications to a particular content type. Is there anything available to pull these taxonomies using Razor?
Thanks!
Stu
Hi Stu,
If you refer to showing the selected taxa on the frontend, you can do this using Feather widgets, as well. It depends on the content type of the item, but the following works on dynamic content and built-in content items (news etc.):
@*Start Tags field*@
<div>
<strong> Tags :</strong>
@
if
(Model.Item.Fields.Tags!=
null
)
<ul @Html.InlineEditingFieldAttributes(
"Tags"
,
"FlatTaxon"
)>
@
foreach
(var taxon
in
Model.Item.GetFlatTaxons(
"Tags"
))
<li>@taxon.Title.ToString()</li>
</ul>
</div>
@*End Tags field*@
@*Start Category field*@
<div>
<strong> Categories :</strong>
@
if
(Model.Item.Fields.Category!=
null
)
<ul @Html.InlineEditingFieldAttributes(
"Category"
,
"HierarchicalTaxon"
)>
@
foreach
(var taxon
in
Model.Item.GetHierarchicalTaxons(
"Category"
))
<li>@taxon.Title.ToString()</li>
</ul>
</div>
@*End Category field*@
<div>
Tags: @
string
.Join(
", "
, Model.Item.GetFlatTaxons(
"Tags"
).Select(t=> t.Title))
</div>
<div>
Categories: @
string
.Join(
", "
, Model.Item.GetHierarchicalTaxons(
"Category"
).Select(t=> t.Title))
</div>
Hi Stu,
Were you able to achieved the desired result?
Regards,
Nikola Zagorchev
Telerik
Yes this is great, thank you!
Hi Stu,
Glad it helps.
Regards,
Nikola Zagorchev
Telerik