Creating Text Snippets in ExpressionEngine Sites
Over time I have developed a tool I call Text Snippets within ExpressionEngine sites I build. Between my text editor’s (Textmate) snippet-pasting ability and ExpressionEngine’s flexibility, this has become one of my favorite tools to use.
Why not use Pages, Global Template Variables or Fresh Variables? A few reasons.
Pages I tend to reserve for full pages of text that may need to be editable by a client. My Text Snippets are usually chunks of text that are somewhere between a sentence and a few paragraphs. One of the most useful placed for Text Snippets is on a page with any kind of form. You may have a form with some textual content above the form, or a disclaimer below the form, or something else, and these may be chunks of text that you want to allow the client to edit. With Text Snippets, they can easily edit this content without affecting the form or anything else on the page that you don’t want them touching.
Fresh Variables and Global Template Variables work great for this type of chunky text, but when was the last time you wanted your client in the Templates tab of the Control Panel? And frankly, I like to keep them out of the Modules tab as much as possible as well. Beyond that, two benefits of Text Snippets over Fresh Variables and Global Template Variables are that they allow XHTML formatting, as with any typical ExpressionEngine entry. Secondly, Text Snippets live where the client is used to going to edit content, in the Edit tab. By using simple naming conventions for your Text Snippets, the client can search for all Text Snippets on a particular page, or in a particular section of the site.
Despite all these benefits, the main shortcoming of Text Snippets is that they become parts of pages that aren’t searchable. You can make the “content” field of Text Snippets searchable, but if it shows up in a search result, where exactly would you send your user to view the page where it lives? I’ve used a few different methods, but it differs based on the client needs.
Well, please enjoy this 10 minute screencast that shows you how to setup and use Text Snippets. I hope you find this to be a useful tool for your ExpressionEngine websites. Also, if you click through to the Vimeo page where the video is hosted, you can download a larger, .mov Quicktime version of this screencast for better viewing if you wish (look on the lower right side of the page).
Here is the code for my snippet in Textmate
{exp:weblog:entries weblog="snippets" url_title="snippet_url_title" disable="categories|category_fields|member_data|trackbacks|pagination" rdf="off" dynamic="off"}
{content}
{/exp:weblog:entries}
This code should work in any editor, and if you editor allows you to place your cursor automatically, be sure to place it between the url_title quotation marks. For best results, be sure to name your weblog “snippets” and your custom field “content”. With these in place, the code above should work flawlessly.

2 Comments
posted on April 08, 2009 at 12:43am by Cem Meric:
Nice screencast Chad. I use this method often to give clients opportunity to update website visual UI etc.
By the way, Noob-EE created an ExpressionEngine group at http://vimeo.com/groups/14026 don’t forget to add your video to it
posted on April 15, 2009 at 3:07pm by Erwin Heiser:
Definitely falls in the “why didn’t I think of that?” category.
Like you I used global or fresh variables for this but using this way I can keep my clients out of those areas… great tip this!
Leave a Comment