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

Forums / Developing with Sitefinity / List of dynamic content by category

List of dynamic content by category

3 posts, 0 answered
  1. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    28 Jan 2014
    Link to this post
    Using module builder, I created a module called Vendors. Each vendor has one or more categories. I'd like to create a control that diplays as follows:

    Category 1
      Vendor 1
      Vendor 2
      Vendor 3

    Category 2
      Vendor 1
      Vendor 4
      Vendor 5
     etc.

    How would I achieve this?
  2. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    05 Dec 2016
    31 Jan 2014
    Link to this post
    Hi Amanda,

    I believe that you can achieve your scenario using the default widget which Module builder creates for your module. I have recorded a short video demonstrating the solution which I think can be helpful.

    http://screencast.com/t/TYRc4rpNH

    Regards,
    Kaloyan
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
  3. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    31 Jan 2014
    Link to this post
    Hi Kaloyan,
    That would work, but requires the end user to add multiple widgets to the page for each category which is not ideal.

    I did find a way to do it with an external template an radlistview/repeater. Below is my code for anyone who might want it.

    Ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AffiliatebyCategory.ascx.cs" Inherits="SitefinityWebApp.Controls.AffiliatebyCategory" %>
    <%@ 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 Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Comments.Web.UI.Frontend" TagPrefix="sf" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Import Namespace="Telerik.Sitefinity.Web.UI" %>
     
    <telerik:RadListView  ID="dynamicContentListView" ItemPlaceholderID="ItemsContainer" runat="server" OnItemDataBound="rptrParent_ItemDataBound">
    <LayoutTemplate>
             
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
           
        </LayoutTemplate>
    <ItemTemplate>
    <h2> <asp:Label ID="Literal5" runat="server" Text='<%# Eval("Title") %>'></asp:Label> </h2>
            <asp:Repeater ID="rptrChild" runat="server">
            <HeaderTemplate><ul></HeaderTemplate>
                <ItemTemplate>
                 
                    <li><sf:DetailsViewHyperLink ID="DetailsViewHyperLink" TextDataField="Title" runat="server" data-sf-field="Title" data-sf-ftype="ShortText" /> <%# Eval("City") %>, <%# Eval("State") %></li>
                </ItemTemplate>
                <FooterTemplate></ul></FooterTemplate>
            </asp:Repeater>   
    </ItemTemplate>
    </telerik:RadListView>
    <sf:Pager id="pager" runat="server"></sf:Pager>
    <asp:PlaceHolder ID="socialOptionsContainer" runat="server"></asp:PlaceHolder>

    cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Taxonomies;
    using Telerik.Sitefinity.Taxonomies.Model;
    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using System.Linq;
    using Telerik.OpenAccess;
    using Telerik.Sitefinity.Model;
    using Telerik.Web.UI;
    using Telerik.Sitefinity.Model.ContentLinks;
    using Telerik.Sitefinity.Modules.Libraries;
     
     
    namespace SitefinityWebApp.Controls
    {
        public partial class AffiliatebyCategory : System.Web.UI.UserControl
        {
     
            protected void Page_Load(object sender, EventArgs e)
            {
                var taxonomyMgr = TaxonomyManager.GetManager();
                Taxon amTaxon = GetCategoryByTitle("Affiliate Member");
                IList<HierarchicalTaxon> subCategories = taxonomyMgr.GetTaxa<HierarchicalTaxon>().Where(t => t.Parent.Id == amTaxon.Id).OrderBy(t => t.Title).ToList();
                dynamicContentListView.DataSource = subCategories;
                dynamicContentListView.DataBind();
            }
     
     
            public string GetImageUrl(string propertyName)
            {
                var contentLinks = Eval(propertyName) as ContentLink[];
                var imageContentLink = contentLinks.FirstOrDefault();
                var librariesManager = LibrariesManager.GetManager();
                var currentImage = librariesManager.GetImage(imageContentLink.ChildItemId);
                return currentImage.MediaUrl;
            }
            public Taxon GetCategoryByTitle(string title)
            {
                var taxonomyMgr = TaxonomyManager.GetManager();
     
                HierarchicalTaxonomy category = taxonomyMgr.GetTaxonomies<HierarchicalTaxonomy>().Where(x => x.Name == "Categories").SingleOrDefault();
     
                if (category == null)
                {
                    return null;
                }
     
                return category.Taxa.Where(x => x.Title == title).SingleOrDefault();
            }
     
            public Taxon GetCategoryByID(Guid id)
            {
                var taxonomyMgr = TaxonomyManager.GetManager();
     
                HierarchicalTaxonomy category = taxonomyMgr.GetTaxonomies<HierarchicalTaxonomy>().Where(x => x.Name == "Categories").SingleOrDefault();
     
                if (category == null)
                {
                    return null;
                }
     
                return category.Taxa.Where(x => x.Id == id).SingleOrDefault();
            }
     
     
            protected void rptrParent_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
            {
                RadListViewItem item = e.Item;
                if ((item.ItemType == RadListViewItemType.DataItem) || (item.ItemType == RadListViewItemType.AlternatingItem))
                {
                    Repeater rptrChild = (Repeater)item.FindControl("rptrChild");
                    Guid catid = new Guid(DataBinder.Eval(((RadListViewDataItem)e.Item).DataItem, "Id").ToString());
                    Taxon amTaxon = GetCategoryByID(catid);
     
                    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                    Type vendorType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.VendorResourceGuide.Vendor");
                    var myItems = dynamicModuleManager.GetDataItems(vendorType)
                                                        .Where(d => d.GetValue<TrackedList<Guid>>("Category").Contains(amTaxon.Id)
                                                                    && d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
     
                    rptrChild.DataSource = myItems;
                    rptrChild.DataBind();
                }
            }
         
         
           
        }
    }
3 posts, 0 answered