November Happy Hour will be moved to Thursday December 5th.

Custom view for content area issue

Vote:
 

Hi,

I'm trying to create a custom view for a content area that should only be used in view mode.

Logical solution would be

[UIHint(UiHint.NoWrappersContentArea, PresentationLayer.Website)]
public virtual ContentArea MainContentArea { get; set; }

Just for the sake of testing I created this view in the DisplayTemplates folder

@model EPiServer.Core.ContentArea

This whould only be visible in view mode, not in edit mode.

Expected behaviour would be that this custom view would only be used in view mode (PresentationLayer.Website). However it is used in both view and edit mode.

Am I missing something here?

Thanks,

Mark

#123625
Jul 10, 2015 15:15
Vote:
 

Hi,

Have you tried to add another UIHint? Like this:

[UIHint(UiHint.NoWrappersContentArea, PresentationLayer.Website)]
[UIHint("ContentArea", PresentationLayer.Edit)]
public virtual ContentArea MainContentArea { get; set; }
#123628
Jul 10, 2015 16:01
Vote:
 

Hi Mattias,

Yes I have.

Unfortunately with the same result.

#123629
Jul 10, 2015 16:07
Vote:
 

I usually don't want the editors to have one experience in Edit mode and another in view mode so I try to avoid it as much as possible. I know it works on some Property types though. I guess ContentArea is not one of them if you can't get it to work. If I need a special display template I try to make sure it is supported in edit mode as well. You can add attributes to the children of the content area to make them editable. Just add data-epi-block-id="123" where the number is a ContentReference.

#123632
Edited, Jul 11, 2015 21:28
Vote:
 

Thanks for the suggestion of using data-epi-block-id. That works perfectly and gives me editing capabilities again when using a display template.
However I have to add this attribute to all my blocks, which I do not prefer. But I will definitely keep this in mind for future usage.

For now I will use a quick workaround which I should have thought of immediately:

@model EPiServer.Core.ContentArea

@if (PageEditing.PageIsInEditMode)
{
    Html.RenderContentArea(Model);
}
else
{
    Html.RenderNoWrappersContentArea(Model);
}


Thanks for your support!

#123633
Jul 11, 2015 23:01
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.