HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Add editing attributes

Describes how to add editing attributes for content rendering in a template, when working with Optimizely Content Management System (CMS).

When you work with content data in Optimizely Content Management System (CMS), the default way to render content in a template is to use the PropertyFor helper, @Html.PropertyFor (see EPiServer.Web.Mvc.Html.PropertyExtensions.PropertyFor in the class library), which is responsible for adding the required HTML to be editable in the content editing view.

However, if you render your content some other way, ensure the output contains the HTML attributes required by the content editing view.

Apply edit attributes to an element

The best way to add the required attributes for editing is to use the EditAttributes HTML helper. Add a wrapping HTML element around the rendered content and call EditAttributes on it.

Apply full refresh properties

Some properties can affect the rendering of several parts of the page. For instance, you may have a Boolean value on your page type that enables or disables several panels. To get a correct preview of such a property, you would need to refresh the page fully.

To make a set of properties force a full reload on change, use the HTML helper FullRefreshPropertiesMetaData. It  renders an HTML element for properties registered in the EPiServer.PageBase.FullRefreshProperties collection.

The following example shows how to use these methods in a template:

@Html.FullRefreshPropertiesMetaData(new[] { "ShowBanner" })
<h1 @Html.EditAttributes(x => x.Heading)>
  /* Render the Heading property, unless it it empty, then use PageName as fallback */
  @Model.Heading ?? @Model.PageName
@Html.PropertyFor(x => x.CurrentPage.MainBody)
using System;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAnnotations;

namespace CodeSamples {
  public class MyPageType: PageData {
    public virtual string Heading {
    public virtual XhtmlString MainBody {
    public virtual bool ShowBanner {