News list widget template - how to get category hyperlink
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"
/>
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:
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;
Thanks. I will wait for this functionality, rather than implement my custom external template at this point.