Snippets in Orchard Layouts

Snippets in Orchard Layouts

Orchard Layouts is new to Orchard CMS 1.9 and one of the features it contains is snippets. I wasn't sure how useful snippets would be given they don't include an editor, but depending on the website they can be very useful for inserting reusable, stand-alone HTML fragments into the orchard website.

What Are Snippets?

Snippets are harvested shapes in the orchard website's theme that follow a particular naming convention. When they are discovered they are represented as Snippet Elements and displayed as icons with their names under the "Snippets" Category of the layout editor's toolbar. Just like other elements, you can drag-and-drop the snippets onto the layout canvas and the corresponding shapes will be displayed on the orchard website.

Snippets currently don't have editors, which differentiate them from custom elements. They are self-contained razor views ( shapes ) that are exposed to the layout editor via a harvester. There is no opportunity for the user to populate any fields that may change the behavior or contents displayed by the snippet on the orchard website. I think this could be changed in the future.

Custom Snippet in Orchard Layouts - Orchard CMS 1.9

Snippets are Reusable, Stand-Alone Shapes

Depending on the orchard website and the needs of the client, snippets in orchard layouts can be very useful as a means of displaying reusable, stand-alone HTML fragments throughout the website.

One of my current orchard projects, for example, has a need for the client to add the newsletter signup at various locations within pages for an article, book, podcast, video, etc. The HTML for the newsletter signup is stand-alone and constant and a perfect fit for snippets. The client just drags the "Subscribe to Newsletter" Snippet onto the layout canvas.

Orchard Layouts

Snippets vs. Custom Elements

As mentioned before, snippets get added to the layout toolbar as Snippet Elements and contain no editor. This makes them currently much less flexible than custom elements that can have an editor and allow the user to interact with them. I recommend you think long and hard about making something a snippet because of this lack of flexibility. You may end up having to replace numerous occurences of a snippet if it turns out you need the flexibility of a custom element.


Although less flexible than custom elements, I find snippets a very useful feature in orchard layouts for placing resuable, stand-alone shapes throughout the orchard website. Snippets are also very easy to implement and expose to the client for use in their orchard layouts.

I am an Orchard Web Developer for hire. If you're interested in an Orchard Website, custom Orchard Modules, and/or Orchard Themes, please contact me.