Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
When working with content data in EPiServer CMS, the default way to render content in a template is to use the
property web control, <EPiServer:Property> (see
So a common scenario would be to add a wrapping HTML element around the rendered content. Set runat="server" on the element and call the property from the code behind.
<EPiServer:Property PropertyName="MyProperty" runat="server" />
The best way to add the attributes required for editing is to use the method EPiServer.Web.ApplyEditAttributes. It is an extension method to the System.Web.UI.Control class. Add a wrapping HTML element around the rendered content. Set runat="server" on the element and call ApplyEditAttributes on it from the code behind.
Some properties can affect the rendering of several parts of the page. For instance, you may have a boolean value on you page type that enables/disables several panels. To get a correct preview of such a property you would need to do a full refresh of the page.
To make a set of properties force a full reload on change, use the web control EPiServer.Web.WebControls.FullRefreshPropertiesMetaData. It will render an HTML element for all properties registered in the collection EPiServer.PageBase.FullRefreshProperties.
The following example shows how to use these methods in a template:
<EPiServer:FullRefreshPropertiesMetaData runat="server" />
<h1 runat="server" id="HeadingOne">
<%-- Render the Heading property, unless it it empty, then use PageName as fallback --%>
<%: CurrentPage.Heading ?? CurrentPage.PageName %>
</h1>
<EPiServer:Property Runat="server" PropertyName="MainBody" />
using System;
using EPiServer;
using EPiServer.Core;
using EPiServer.Web;
using EPiServer.DataAnnotations;
namespace CodeSamples
{
public partial class CustomEditHints : TemplatePage<MyPageType>
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Connect the content div to the Heading property of MyPageType
HeadingOne.ApplyEditAttributes<MyPageType>(p => p.Heading);
// Register the ShowBanner property for full refresh preview
EditHints.AddFullRefreshFor(p => p.ShowBanner);
}
}
[ContentType]
public class MyPageType : PageData
{
public virtual string Heading { get; set; }
public virtual XhtmlString MainBody { get; set; }
public virtual bool ShowBanner { get; set; }
}
}
Last updated: Feb 23, 2015