Equivalent of Documents macro in ascx transformation?

Tom F asked on January 6, 2017 01:02

Is there the equivalent to Documents in an ascx transformation? it doesn't seem to be available?

I'm finding myself doing things like this in CMSTransformations.cs and it feels a bit wrong:

public TreeNode CurrentItemParent()
{
    var dataRow = ((DataRowView)this.DataItem).Row;
    if (dataRow != null)
    {
        var itemAsTreeNode = CMS.DocumentEngine.TreeNode.New(dataRow);
        return itemAsTreeNode.Parent;
    }

    return null;
}

Correct Answer

Roman Hutnyk answered on January 6, 2017 08:44

ASPX transformation is similar to user control layout and you should be able to call any server side code from it like this:

<%# CMS.DocumentEngine.DocumentHelper.GetDocuments().WhereEquals("NodeID",Eval("ParentNodeID")).FirstObject%>

In fact this is similar to using transformation methods.

Also this approach is not the best from performance stand point - it makes database call for each item in the list, so it is better to implement custom query or custom data source, so it will return data structure you need at once, so no need for extra calls to database.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Adam Gitin answered on January 6, 2017 06:55

Regarding macros in ascx transformations, you can resolve them using API: https://docs.kentico.com/plugins/servlet/mobile#content/view/59639072

You can also use text/XML transformation and just use macros.

Also be sure to check out Kentico out of the box functions:https://docs.kentico.com/k9/developing-websites/loading-and-displaying-data-on-websites/writing-transformations/reference-transformation-methods

1 votesVote for this answer Mark as a Correct answer

Tom F answered on January 6, 2017 12:09

Thanks to you both most appreciated :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.