+1-888-365-2779
Try Now
More in this section

Forums / Designing & Styling / Category classification in custom widget template

Category classification in custom widget template

4 posts, 0 answered
  1. Nico
    Nico avatar
    4 posts
    Registered:
    05 Mar 2013
    23 Oct 2013
    Link to this post
    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!
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    30 Nov 2016
    28 Oct 2013
    Link to this post
    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" />
    The ID highlighted here is the ID of the Categories classification if you are using different hierarchical classification place its Id at the highlighted part.
    This control renders the names of the categories as strings.

    Regards,
    Stanislav Velikov
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Nico
    Nico avatar
    4 posts
    Registered:
    05 Mar 2013
    28 Oct 2013 in reply to Stanislav Velikov
    Link to this post
    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?


  4. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    30 Nov 2016
    31 Oct 2013
    Link to this post
    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));
               }

    Regards,
    Stanislav Velikov
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered