BranchCMS Upgrades

Eric Tompkins
Mar 7, 2011

Introducing Content Snippets

If you've edited any pages in your website recently you might have noticed a new section of Pages called Content Snippets. I'm going to explain what Content Snippets are, why we created them and what you can do with them.

Content Snippets

Content Snippets do pretty much what their name says, they let you create snippets of content to use in other parts of your website. The difference between Content Snippets and Snippets underneath Site Manager is that with Content Snippets you can use the rich-text editor to enter content or you can use an existing Page Content Block Layout. This gives a lot more flexibility and control over the content.

And just like Snippets there is an API tag to include that Content Snippet anywhere on your website.

{ap_api:page:contentSnippet key="snippetKey"}

Why we did it

The idea for creating Content Snippets came out of our own frustrations when building websites for our partners. For one recent job we needed to include a portion of editable content on top of the search form used on each page of the Real Estate section of the website. The content was going to be the same every time the form was shown, but the client needed to be able to edit the content. The way that we've solved this type of thing in the past was to create a page that wasn't published and then use the page API to pull in the content where it was needed. While this worked just fine, it seemed a little hacky. We finally said "enough is enough" and put our heads together to come up with a better solution. Content Snippets was our answer.

One option that we had was to add the capabilities that Content Snippets have to regular Snippets underneath the Site Manager section. However, we chose not to do that for a couple of reasons. The first is that we felt that going to Site Manager -> Snippets was out of the way and that most things under Site Manager are intended for developers and not content editors. The second was that we wanted to keep Snippets for the simple reason that they were created, to hold snippets of HTML, not snippets of content. Also by creating Content Snippets and putting them under Pages it made sense to allow them to use Page Content Block Layouts.

So what can you do with Content Snippets?

One use would be to solve the exact problem that we were running into, making it easy to manage reusable content on an app page. You could also use them to create "editable areas" of a template that are used site wide.

Difference with Pages

Although Content Snippets and Pages can use Page Content Block Layouts, it's important to note one major difference in how Page Content Block Layouts are used. When a Content Block Layout is used with a Page, the content is fully rendered and saved at the time that the page is saved. This means that the Content Block Layout is not dynamic and processed each time the page is viewed on the website. This is a known limitation and we do plan on changing that. Because of that we did Content Snippets a little differently. Instead of rendering the Content Snippet content once and saving it as static content, each time a Content Snippet is loaded into a page the Content Block Layout is processed. This makes Content Snippets dynamic and they can react to things like the page URL, parameters in the page URL or if an account is logged in.

Of course, if you're just using the rich-text editor instead of a Content Block Layout then none of that applies.

Sign up for our newsletter to receive invaluable information about BranchCMS, web design & development.