9

It's not at all uncommon to have an article page designed that is intended to be dynamically formed from a number of components:

<rich text>
<left image with additional comment>
<rich text>
<image gallery>
<rich text>
... etc

The gallery might be reusable, and thus point to an existing item, but the rich text certainly is not intended to be. This can't be approached out of the box, since the rich text field needs to render a field, so each instance will simply render the same text.

What is the recommended pattern to achieve this?

I see three possible solutions:

Create a data source item for each component

This can be done out of the box if the author creates the data source items manually, but doing so is so arduous that it's no longer worth using the Experience Editor at all.

It's possible to automate this, which is effectively what Adobe Experience Manager does, but in Sitecore it involves custom code to dynamically create the item when a rendering is added to the page. There's also no way to skip the "select data source" dialog, so the editing experience is disjointed.

Having implemented this method, I can also vouch for it being particularly painful with regard to workflow and publishing since the state of each data source needs to be kept in sync with the page.

Allow selection of renderings within the Rich Text Editor

This method was outlined by John West back in 2010 and involves using custom pipelines to include renderings embedded within a Rich Text Editor.

I'd say this approach would take a fair amount of work to get right to avoid the WYSYWG editor accidentally allowing, for example, a rendering inside a <p><strong> tag.

Considering there has been not much discussion of this method since that blog post, and John takes pains to state that it's not supported, it's safe to assume that this is not considered best practice.

There are almost no upsides to this approach.

Include the rich text as a Rendering Parameter

In this approach the rich text is kept in a rendering parameter via a Rendering Parameter Template.

This is, more or less, how Umbraco 7 solves this problem.

In theory this could work, since Final Layout in SC8+ is versioned so it can be localised. It makes it impossible to share the content elsewhere, and may require index customisations, but those might be acceptable.

Richard Seal recommends against this approach in my question around this approach.

Restrict the UX

This is the "Sitecore can't do that" option. Obviously not ideal, since people pay for expensive CMSs so they can have flexible control over their site's content.

1 Answer 1

4

The best way to do this is for each element on the page to be a separate rendering with its own data source item.

The page item should have minimal content from its own fields. Things like the Title and Meta, include in sitemap or robots.txt rules.

When a rendering is added to a page (Can be as simple as a single 'content' placeholder in the main Layout) the datasource can be selected or created at that time. Renderings can include their own inner placeholders to provide more flexibility. I would recommend using Dynamic Placeholders in these cases.

If your data is organized into template specific folders and your renderings have the appropriate Data Source Template and Data Source Location values, this operation is actually pretty smooth. Workflow of rendering data source items can be managed with this module: https://marketplace.sitecore.net/Modules/D/Data_Source_Workflow_Module.aspx?sc_lang=en

I also set up my renderings with some extra help text or formatting when Sitecore.Context.PageMode.IsExperienceEditorEditing == true so it is easier to edit a newly created item within Experience Editor.

You can also set the presentation of the page template standard values to give it some default renderings and data sources.

Your Answer

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

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