Content Area property items allows to select Display Options. Display options let Editor specify how item should be renderred in the view mode. When adding content to a Content Area, we usually know which display option will be the best choice based on content type. For example our ButtonBlock will be best displayed as Narrow while Editorial block as Wide. That’s why I prepared a small javascript snippet to set Content Area default display options.

Content Area default display options overview

The code is a dojo initialization module that can be used in Episerver CMS 12 project.

To use it, just modify the resolveDisplayOption method. The method should return default DisplayOption when value should be set name or null when display option should not be set. DisplayOption can be specified based on three input parameters:

  • currentContent – currently edited content object. You can for example check content type name (currentContent.typeIdentifier)
  • propertyName – name of the edited property
  • item – content area item object. You can for example check item content type name (item.data.typeIdentifier)

In the example below, the display options return value will be set only for “mainContentArea” property on Start Page content type. For “Page list” block types it will be set to “wide” display option and for “Teser” it will set to “narrow” display option. For other peoprties and page types the default display option won’t be set.

The snippet is extending three ContentArea methods:

  • when using “Select Content” command
  • when doing drag and drop at the end of ContentArea
  • when doing drag and drop between items

It does not change the method bechaviour, but applying display options after the method was called.

It supports dropping multiple blocks to content area.

The snippet initialization module source code:

On the GIF below you can find how deafult options are set when dropping two block into content area:

Using Content Area default display options

The same code is also available as github gist