How to inherit editable region content when using ASPX templates

   —   
This article will show you how to correctly inherit content of an editable region on a sub page, when using ASPX page templates.
In previous versions of Kentico CMS, the InheritContent property allowed you to inherit content when using the Portal engine, as well as ASPX templates. However, using the InheritContent property in ASPX templates didn’t always work correctly, since the tree structure in ASPX page templates was unknown.  The code snipped below allows you to work around this problem:

Place this code into the ASPX code of your page template, where you want to have inherited content:

<cms:CMSEditableRegion runat="server" ID="TopText" RegionType="HtmlEditor" RegionTitle="Top content text" InheritContent="true" />
<asp:PlaceHolder runat="server" ID="plcContent">
<asp:Literal ID="ltlRegion" runat="server" Visible="false"/>
</asp:PlaceHolder>

Then, in the code behind of the template, use this code to load the content to the label:

protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

           // If it is some child document (not root)
            if (CMS.CMSHelper.CMSContext.CurrentPageInfo.NodeLevel > 0)
            {
                CMS.PortalEngine.PageInfo parentpi = CMS.PortalEngine.PageInfoProvider.GetPageInfo(CMS.CMSHelper.CMSContext.CurrentSiteName, "", CMS.CMSHelper.CMSContext.CurrentDocumentCulture.CultureCode, "", CMS.CMSHelper.CMSContext.CurrentPageInfo.NodeParentId, false);
                // Show label for editable region content
                this.ltlRegion.Visible = true;
                // Hide editale region control
                this.TopText.Visible = false;
                this.ltlRegion.Text = CMS.GlobalHelper.ValidationHelper.GetString(parentpi.EditableRegions[TopText.ID.ToLower()], "");
                CMS.ExtendedControls.ControlsHelper.ResolveDynamicControls(this.plcContent);
            }
       
    }
-jo-


Applies to: Kentico CMS 6.x
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.