You can use any type of control that outputs an element, meaning it must inherit from either WebControl or HtmlControl. For instance a Label works but not a Literal.
If you do that you can set its value to the Heading property like you do with the Literal above. Finally you can use the ApplyEditAttributes method to make it act as a property container for editing, like this:
labelHeader.ApplyEditAttributes(x => x.Heading)
If you do this the property will be rendered with fallback but if the editor clicks on it an empty textbox will appear (if they haven't entered a Heading) where they can enter the Heading.
Thanks.
I found that this did not work in a MasterTemplate, but did inside a user control and aspx page.
As a note, the code behind page needs the using statements
using EPiServer.Web;
using EPiServer.DataAnnotations;
and the code to populate the control is (here with an extension to HTML encode the output)
hdrTitle.InnerText = CurrentPage.Heading.ToWebString();
hdrTitle.ApplyEditAttributes<Models.Pages.BasePageData>(p => p.Heading);
What is the best way to display a page property in a template or page, that will allow an editor to edit the value, but for a site visitor the fall back value will be displayed.
In a MasterTemplate, I want to display the page Heading (to show result I have put both a literal and then "//" and the EPiServer Property tag. The EPiServer property tag does not display the PageName (there is no value for Heading on this page.
The page property code is:
The code behind for the template is
The only way I can think at the moment is to add a test for being in edit mode (if (PageEditing.PageIsInEditMode)...) and hide the approrpriate controls. Is there a better way?