Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Macro to get category name from ID? View modes: 
User avatar
Member
Member
rlull - 11/18/2013 10:33:42 AM
   
Macro to get category name from ID?
Is there a macro to get the category name by passing in the ID?

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 11/18/2013 12:19:33 PM
   
RE:Macro to get category name from ID?
You can try the macro below replacing your ID for the CategoryID in the Filters.
{%GlobalObjects.Categories.Filter("CategoryID == 1")[0].CategoryName.ToString() + 
SiteObjects.Categories.Filter("CategoryID == 1")[0].CategoryName.ToString()%}

User avatar
Member
Member
rlull - 11/18/2013 1:12:17 PM
   
RE:Macro to get category name from ID?
Great, thanks. I also found this one:
{%SiteObjects.Categories.DisplayNames[8]%}

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 11/18/2013 1:43:18 PM
   
RE:Macro to get category name from ID?
You might want to double check that one. The index of the DisplayNames collection might not correspond to the CategoryID.

User avatar
Member
Member
rlull - 11/18/2013 1:53:00 PM
   
RE:Macro to get category name from ID?
You're right. I like your way better but I am not quite able to get what I am after. I have the category ID in the url (parameter "DCI") and want to put that into the macro example you provided. I have tried several different ways. For example:
{% SiteObjects.Categories.Filter("\"CategoryID == " + QueryString.GetValue("DCI") + "\"")[0].CategoryName.ToString() %}

Any thoughts? I thought it was just a matter of getting the quotes right but I've tried every combination I could think of.

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 11/18/2013 2:31:23 PM
   
RE:Macro to get category name from ID?
I can't get it to work as well. Even a simple concatenation does not work...
{%GlobalObjects.Categories.Filter("CategoryID == " + "8")[0].CategoryName.ToString() + SiteObjects.Categories.Filter("CategoryID == " + "8")[0].CategoryName.ToString()%}
This might be a bug for the Filter() string parameter.

User avatar
Member
Member
rlull - 11/18/2013 4:47:20 PM
   
RE:Macro to get category name from ID?
I've submitted this to Kentico to see what they have to say. Meanwhile, I ended up writing a custom macro. I can accomplish this now with:
{% GetCategoryNameFromID(QueryString.GetValue("DCI")) %}

User avatar
Member
Member
rlull - 11/18/2013 5:53:09 PM
   
RE:Macro to get category name from ID?
Kentico's solution:
{% SiteObjects.Categories.Where("CategoryID = " + QueryString.DCI).FirstItem.CategoryName %}

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 11/19/2013 7:30:54 AM
   
RE:Macro to get category name from ID?
Thanks for posting that. Still seems odd that Filter() can't handle the string concat.