Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > categories in article transformation View modes: 
User avatar
Member
Member
alexo - 3/9/2011 10:05:21 AM
   
categories in article transformation
hi,

i need to display the related categories in the article transformation. is it only possible by using a custom transformation function? if yes, how should the function look like? i only know how the sql statement...

thx for your help.



User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 3/9/2011 1:44:29 PM
   
RE:categories in article transformation
Hi,


you can use a control in the transformation. Something like the Shopping cart item selector in: the sample code of e-commerce transformation.

So you can add a control which will display the categories.

Or you could create a custom transformation function, get the needful data and return the HTML output.


Best regards,
Helena Grulichova

User avatar
Member
Member
alexo - 3/22/2011 5:42:00 AM
   
RE:categories in article transformation
srry for the late answer, but i was on holidays.

Or you could create a custom transformation function, get the needful data and return the HTML output.


That was my thinking too, but i don't know how the code must look like in .NET, because i'm just able to do some php coding (i'm the designer :D)....

thx for your help


User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 3/24/2011 9:53:44 AM
   
RE:categories in article transformation
Hello,


You can see the sample code of custom transformation function here: Adding custom functions to transformations.

The custom function can have one argument (actual DocumentId) which you can get if you Eval("DocumentId").


You can get the document categories in the custom transformation function by the API method:

CMS.SiteProvider.CategoryInfoProvider.GetDocumentCategories(int documentID, string where, string orderBy)


The API Reference is here: API reference


Best regards,
Helena Grulichova

User avatar
Member
Member
alexo - 4/14/2011 8:24:02 AM
   
RE:categories in article transformation
thx for the great advice! i added a custom function and my dataset gets the right table (i tested it with the table columns) but it is empty altough i get values in my sql engine (MS Sql Server).

do you have any suggestion about this problem?




User avatar
Member
Member
alexo - 4/14/2011 9:17:34 AM
   
RE:categories in article transformation
i found the reason: my function got the wrong ID -> how do i get the documentid from an article?

CMSContext.CurrentDocument.DocumentID returns always the same ID... (for example 15 for different articles)

thx...

User avatar
Member
Member
alexo - 4/14/2011 9:56:27 AM
   
RE:categories in article transformation
ok - SORRY for posting as much - but now i got it:

during my tests i changed eval("DocumentID") to many other things like numbers, CMS.CMSHelper.CMSContext.CurrentDocument.DocumentID etc. - so just let it be EVAL("DocumentID") because that works great!!

thx a lot for helping me!!

regards

User avatar
Member
Member
mattia.biancardi-gmail - 1/2/2012 1:00:42 PM
   
RE:categories in article transformation
Hi,
this function works (CMS.SiteProvider.CategoryInfoProvider.GetDocumentCategories) but return me a DataSet, not a single value.
How can I print it on script inside a custom transformation?
Now if I use this function inside transformation I see this text: System.Data.DataSet

Let me know

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/3/2012 3:04:19 AM
   
RE:categories in article transformation
Hello,

it returns the dataset because the document can be assigned to more than one categories. You can loop through the dataset, for example like:

StringBuilder sb = new StringBuilder();
// Get document categories
ds = CategoryInfoProvider.GetDocumentCategories(this.DocumentID, "CategoryEnabled = 1", null);
// Check whether exists at least one category
if (!DataHelper.DataSourceIsEmpty(ds))
{

// Loop thru all categories
foreach (DataRow dr in ds.Tables[0].Rows)
{
sb.Append(Convert.ToString(dr["CategoryDisplayName"]) + ",");
}
}
string content = sb.ToString();

Best regards,
Helena Grulichova

User avatar
Member
Member
mattia.biancardi-gmail - 1/5/2012 10:08:13 AM
   
RE:categories in article transformation
I've created inside AppCode the MyFunctions.cs and a function with the code that you suggest.
What using directive I need to include to make this functions works?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/9/2012 8:19:51 AM
   
RE:categories in article transformation
Hello,


the MyFunctions class works for transformations. Please see here. Does it help?


Best regards,
Helena Grulichova