How to get parent page template name from transformation

TRISHUL TANDEL asked on October 12, 2018 18:24

How to get parent page template name in transformation. I am using ascx transformation type.

Correct Answer

Brenden Kehren answered on October 12, 2018 18:52

Not anything you want to do each time a transformation is displayed. Meaning if you're retieving 100 items in a repeater, that code will execute 100 times.

Maybe you want to display the parent page name and not get the template information from the page? If so you can use a macro in your text/html transformation like so:


0 votesVote for this answer Unmark Correct answer

Recent Answers

Peter Mogilnitski answered on October 14, 2018 16:20 (last edited on October 14, 2018 16:23)

Since transformation is essentially a user control you can do something like this:

<%@ Import Namespace="CMS.DocumentEngine" %>
<%@ Import Namespace="CMS.PortalEngine" %>
<%@ Import Namespace="CMS.Helpers" %>
<script runat="server">
string templateName = "";

protected void Page_Load(object sender, EventArgs e)
    if (CurrentDocument == null) return;
    // calculate it only once per request
        var parent = CurrentDocument.Parent;
        var templateID = (parent.NodeTemplateID == 0)? parent.DocumentPageTemplateID : parent.NodeTemplateID;
        var ti =  PageTemplateInfoProvider.GetPageTemplateInfo(templateID);
        CMS.Helpers.RequestStockHelper.Add("templateName", ti.CodeName);
    templateName = ValidationHelper.GetString(RequestStockHelper.GetItem("templateName"), "");      
0 votesVote for this answer Mark as a Correct answer

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