I like the option of just using a method to extract this data although it doesn't leave much room for formatting and/or creating links which is why I opted for this way.
ASCX control:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CategoryListing.ascx.cs" Inherits="Custom_Controls_CategoryListing" %>
<cms:CMSRepeater ID="rptCategories" runat="server" HideControlForZeroRows="true" />
Code behind:
using CMS.SiteProvider;
using CMS.UIControls;
using System;
using System.Data;
public partial class Custom_Controls_CategoryListing : CMSUserControl
{
public string TransformationName
{
get
{
return rptCategories.TransformationName;
}
set
{
rptCategories.TransformationName = value;
}
}
public int DocumentID { get; set; }
public string OrderBy { get; set; }
public string Where { get; set; }
public string TopN { get; set; }
public string ItemSeparator
{
get
{
return rptCategories.ItemSeparator;
}
set
{
rptCategories.ItemSeparator = value;
}
}
protected override void OnPreRender(System.EventArgs e)
{
base.OnPreRender(e);
SetupControl();
}
private void SetupControl()
{
DataSet ds = new DataSet();
// checking here to see if we need to limit it to a specific number or not
if (string.IsNullOrEmpty(TopN))
{
ds = CategoryInfoProvider.GetDocumentCategories(DocumentID, Where, OrderBy);
}
else
{
ds = CategoryInfoProvider.GetDocumentCategories(DocumentID, Where, OrderBy, Convert.ToInt32(TopN), "");
}
rptCategories.DataSource = ds;
rptCategories.DataBind();
}
public void ReloadData()
{
SetupControl();
}
}
Usage in a transformation:
<%@ Register Src="~/Custom/Controls/CategoryListing.ascx" TagName="CategoryListing" TagPrefix="uc1" %>
<uc1:CategoryListing runat="server" ID="CategoryListing" ItemSeparator="," TransformationName="cms.blogpost.BlogCategories" DocumentID='<%# ValidationHelper.GetInteger(Eval("DocumentID"), 0) %>' />
The transformation for the CategoryListing control (cms.blogpost.blogcategories)
<%# (DataItemIndex == 0 ? " in " : "") %>
<a href="<%# "~/Blog/Category/" + Convert.ToString(Eval("CategoryDisplayName")).Replace(" ", "-") %>"><%# Eval("CategoryDisplayName") %></a>
I use dynamic URLs for the Blog page that have the Category name in place so they are friendly URLs vs. catID=2 or something usless like that. I also modified the TagCloud webpart to do the same thing and use friendly URLs.
Its a bit dissapointing to me to be able to set "friendly URLs" in the Site Manager but it doesn't apply across all modules (i.e.: blogs, forums, etc.)