When you find yourself writing the same peace of html again and again or have some content that you write in the rich text editor that always should look the same but maybe with difference in text, you should consider making a snippet.
A snippet is a small peace of html that can be pasted into a html field in two clicks of your mouse.
And by using it you are sure that the html surrounding your text is always the same.
How to create a snippet
The way to create a snippet differs in Sitecore 5 and 6. The difference is in the database where the snippet is defined. In Sitecore 5 the snippets are defined in the master database and in Sitecore 6 the snippets are defined in the core database. Other than that the procedure is the same.
To access the core database, login to the desktop and use the database selector in the in the lower rigth corner next to the clock.
The snippets are defined in the snippet folder located here:
/sitecore/system/Settings/Html Editor Profiles/Rich Text Full/Snippets
It could be that one of the other html editor profiles are used for the html field. If so you should create the snippet under this profile.
Create a snippet using the following template:
/sitecore/templates/System/Html Editor Profiles/Html Editor Snippet
This template consists of two fields, a header field and a value field.
In the header field you can write the name the editor will se when they choose the snippet and in the value field you input the html that should be pasted into the html field when the editor chooses the snippet.
You are done! You have created a snippet. Now its time to use it. Remember to change Sitecore back to the master database.
How to use a snippet
This is the easy part, as it should be, after all wasn't that the purpose of creating snippets.
Go to the item where you want to use the html from the snippet and open the html editor.
When you press the ”Insert Code Snippet” button you will see the new snippet that you have just created.
When you press ”My Snippet” the html from the value field of the snippet is inserted into the html editor. It's that easy.
I will end this article with a little warning. When you use snippets, make sure you get the html in the value field correct before you let anyone use the snippet. When it is use in 200 different items and you discover a mistake, fixing the snippet will not change the html in the items where it has been used.
Happy snippet creating, and thanks for reading this article.