Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

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) {
        <h3>@Html.SiteEditField(Model.Component,Model.Component.Fields["SubHeader"])@SubHeader</h3>
    }
else
{
}

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
This is definitely the easiest option! –  Rob Stevenson-Leggett Aug 18 at 9:50

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?

http://www.tridiondeveloper.com/having-fun-with-experience-manager

share|improve this answer
1  
Checking the Request.Referrer.ToLower() contains "siteedit" works too –  Rob Stevenson-Leggett Aug 6 at 14:27
    
Thanks for the addition Rob. I've incorporated it into the answer. –  Nickoli Roussakov Aug 6 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. –  Albert Romkes Aug 7 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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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