Thursday, May 19, 2016

Sitecore snippets are great for reusable HTML blocks

During a migration from an older system to Sitecore, I ran into an issue where there were large chunks of HTML being used to render content. These chunks needed to be reusable and inserted by content editors as needed. The solution was using snippets in the rich text editor:

Sitecore rich text editor - insert snippet

These snippets are defined under rich text editor profiles - which are found in the core database under: /sitecore/system/Settings/Html Editor Profiles.

An example snippet is available under the rich text full profile (/sitecore/system/Settings/Html Editor Profiles/Rich Text Full). If you look under this item, there will be a folder called snippets, and in there a sample snippet.

Location of Sitecore sample snippet

This item is of the template HTML Editor Snippet (/sitecore/templates/System/Html Editor Profiles/Html Editor Snippet) and contains 2 fields:

  • Header: What displays in the rich text editor
  • Value: The HTML block to be inserted
Sample Sitecore snippet
An example with HTML is:
Sitecore snippet with HTML
My previous post on rich text editor profiles explains how these profiles can be set by default on al rich text fields or on individual instances of a field. In one multi site instance of Sitecore, I set a different profile on the base content item for each site - this allowed them to have their own custom snippets.

No comments:

Post a Comment