I have a page which has optional field called "SubHeader" that does not contain any text. I want to add the value of that field using experience manager. Here is my code

      string SubHeader = (Model.Component.Fields.ContainsKey("SubHeader")) ? Model.Component.Fields["SubHeader"].Value : String.Empty;
    @if (SubHeader != String.Empty) {

In my scenario the value of the Field is empty. Here 'else' block will be executed. I want to write some code in this block to add the values to SubHeader Field. If anybody can suggest the better way to do this.

3 Answers 3


You can modify the content inline through experience manager only when it is showing on your web page. Then content which is not showing can be edited by form view.

You can refer the documentation on SDL live Content Website.


The conundrum here is that the optional field isn't rendered in your CP when empty, so XPM doesn't overlay its editing over what isn't rendered. Therefore you have two options:

  1. Open the component in Form View and add the optional text, then the field will show up via xpm.
  2. Render the optional fields in your CP (xpm puts some default text like "add text here") in the empty ones.

In order to do option 2 in a way to not deviate from the markup you desire in the end, you need to do a trick: on the Preview site where XPM is enabled, render the field in a flyout or modal popup for inline editing purposes. You will need to be able to do some conditional logic in your view to determine if the site is XPM enabled to render this extra stuff. For this you can:

Here are some more resources on this topic for you to poke at: What is the XPM markup for rendering a Component Link Wrapper component with separate link text from Component Link?


  • 1
    Checking the Request.Referrer.ToLower() contains "siteedit" works too Aug 6, 2014 at 14:27
  • Thanks for the addition Rob. I've incorporated it into the answer. Aug 6, 2014 at 18:48
  • 1
    Maybe it's worth noting that Request.Referrer.ToLower() doesn't work if the user presses 'Update Preview'. It only works when loading the page in the XPM IFrame. Aug 7, 2014 at 6:17

You can also add defaults to the schema or to the Content Type for new pages that use this header. Custom Content Types are optional, but can give you additional variations of the same header (with no schema or template changes).

When authors delete the text, they may not be able to edit the text. In that case, have them remove the header instead. Or if dynamic, they could right-click and unpublish the DCP (but that only lasts until the next page publish).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.