Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Accessing other Kentico Objects inside transformations View modes: 
User avatar
Member
Member
lancetek - 5/24/2011 7:52:28 AM
   
Accessing other Kentico Objects inside transformations
I'm doing an article transformation, and I need to get to some custom fields of the article's author (Owner). In looking at the article dataTable that's returned from the db, it has the NodeOwnerUserName field.

How can I get to the Owner's information inside the transformation?

Their are 2 ways that I can think of:
1 - Don't use a transformation and write my own usercontrol to display the article.
2 - Alter the select query used by the transformation, joining in the cms_user table.

Is there a *magic* way to use a macro in a transformation to fetch related object info like this?

What is the recommended way to access other Objects within a transformation?


Thanks,
Lance


User avatar
Member
Member
kentico_michal - 5/24/2011 8:49:22 AM
   
RE:Accessing other Kentico Objects inside transformations
Hello Lance,

You could take advantage of creating a custom transformation method. You can pass the UserID of the article owner to the transformation. Since this information is stored in the NodeOwner field, you can use the following expression:

<%# MyFunctions.TransformationName(Eval("NodeOwner")) %>

Then you will need to create the UserInfo object based on the UserID:

UserInfo user = UserInfoProvider.GetUserInfo(UserID);


Now you can access all properties of the owner and return them according to your need.

If you need more information about custom transformation method I would like to point you to the following article:
Adding custom functions to transformation

or

to API reference:
Kentico CMS API reference


Best regards,
Michal Legen