Category classification in custom widget template
Hi all,
Using the module builder I created a custom content type (let's say "Product") with a classification based on categories. This works well. Now I'm trying to create a custom widget template for this. I am working on the list view that requires the Products to be listed, grouped by category. I haven't been able to create this so far. This is what I have now:
<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<telerik:RadListView ID="dynamicContentListView" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false" GroupPlaceholderID="GroupsProductsContainer">
<LayoutTemplate>
<section class="presentation-blocks">
<asp:PlaceHolder ID="GroupsProductsContainer" runat="server"></asp:PlaceHolder>
</section>
</LayoutTemplate>
<GroupTemplate>
<ul>
<h2>(Category Name)</h2>
<asp:PlaceHolder ID="ItemsContainer" runat="server"></asp:PlaceHolder>
</ul>
</GroupTemplate>
<ItemTemplate>
<li>
<a href="#">
<div class="block-canvas">
<span class="label"><sf:DetailsViewHyperLink ID="DetailsViewHyperLink" TextDataField="Title" runat="server" /></span>
</div>
</a>
</li>
</ItemTemplate>
</telerik:RadListView>
<sf:Pager id="pager" runat="server"></sf:Pager>
<asp:PlaceHolder ID="socialOptionsContainer" runat="server"></asp:PlaceHolder>
How can I group on category classification and display the category-name on the desired place (see "GroupTemplate")?
Thanks!
Hello,
To render the names of the categories assigned for each item in the list template, edit the list template and use HierarchicalTaxonField control to render the categories for the item.
<
sitefinity:HierarchicalTaxonField
ID
=
"HierarchicalFieldControl"
runat
=
"server"
TaxonomyId
=
"E5CD6D69-1543-427b-AD62-688A99F5E7D4"
DisplayMode
=
"Read"
WebServiceUrl
=
"~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc"
Expanded
=
"false"
TaxonomyMetafieldName
=
"Category"
ExpandText
=
"ClickToAddCategories"
BindOnServer
=
"true"
/>
Hi Stanislav,
Thank you for your reply. So if I understand your reply correctly this renders the name of the category? Does it also sort items based on their category and display these items ordered by category?
So a structure like:
*Categoryname*
- Item 1
- Item 2
- Item 3
*Categoryname*
- Item 4
- Item 5
- Item 6
This type of structure is what I'm looking for. I can, of course, place 5 list-widgets on the page but that would require me to make 5 separate widget templates. Due to design choices, that would take too long to explain here. So I'd prefer not to. Is this structure possible with one single widget?
Hello,
The category display field renders the list of categories for each item, here is a screenshot because for example the widget that displays a list of items will add categories to each item in the list
To create a custom control that will display a list of all categories and what items those categories are assigned to. The query to retrieve the items of particular type (I used News items) that are classified with specific category use the query below.
using
Telerik.Sitefinity.Model;
var manager = TaxonomyManager.GetManager();
var newsManager = NewsManager.GetManager();
//retrieve all categories
var categoriesTaxa = manager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);
var taxomonyList = categoriesTaxa.Taxa;
foreach
(var item
in
taxomonyList)
//category name
var categoryName = item.Name;
//get the news items assigned to category
var collection = newsManager.GetNewsItems().Where(n => n.GetValue<TrackedList<Guid>>(
"Category"
).Contains(item.Id));