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

Forums / Developing with Sitefinity / News list widget template - how to get category hyperlink

News list widget template - how to get category hyperlink

3 posts, 0 answered
  1. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    09 May 2013
    Link to this post
    I'm displaying categories field in my custom widget template for News List.  How do I make the categories hyperlinks so they can filter the news list according to the clicked category?  This functionality was built-in before SF 4, I believe.

    Here's my field for displaying categories in widget template?

    <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" />

    p.s.  I know I can filter by category by dropping a Categories widget.  I'm already doing that.  But it makes sense that when someone is viewing an article and seeing its categories, he/she can click on it right there and view all other news stories of same category.
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    09 Dec 2016
    14 May 2013
    Link to this post
    Hi Marko,

    Thank you for contacting Telerik Support.

    As you properly pointed out , indeed this functionality has not been implemented yet in the new Sitefinity  architecture. As such it is currently logged as a a feature request in our system, you can track its status and vote for its popularity in PITS here.

    In the meantime  you can achieve this with an external widget template which will have a control to render the click-able output (e.g. Literal) and in its code behind you can implement a method that will construct the correct filtering URL parameters, here's a similar example that might help you get started:
    Copy Code
    public string RenderHierarchicalTaxaAsLink(NewsItem newsitem, string taxonomyFieldName)
           {
      
               var catList = "";
               var categories = newsitem.GetValue<TrackedList<Guid>>(taxonomyFieldName);
               if (categories != null && categories.Count() > 0)
               {
                   catList = "Categories:</br> ";
                   var currentUrl = HttpContext.Current.Request.Url.ToString();
                   if(currentUrl.EndsWith("/"))
                   currentUrl = currentUrl.TrimEnd('/');
                   var taxManager = TaxonomyManager.GetManager();
                   foreach (var cat in categories)
                   {
                       var t = taxManager.GetTaxon<HierarchicalTaxon>(cat);
                       var url = string.Format("{0}/-in-{1}/{2}/{3}",currentUrl, t.Taxonomy.TaxonName, t.Taxonomy.Name, t.Name);
                       var link = string.Format( "<a href='{0}'>{1}</a><br/>", url, t.Name).ToString();
                       catList = catList + link;
                   }
               }

    Please do not hesitate if there's anything else I can assist you with, or if you have any further question on the above sample, I'll be glad to help.

    Greetings,
    Boyan Barnev
    the Telerik team
    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. Marko
    Marko avatar
    148 posts
    Registered:
    30 Jul 2008
    14 May 2013
    Link to this post
    Thanks.  I will wait for this functionality, rather than implement my custom external template at this point.
3 posts, 0 answered