Using Snippets

A snippet is a reusable block of text or code. You can create as many as you’d like and reference them by name in your templates and pods. Snippets can include HTML, JavaScript, and Textile code. Note that snippets can include other snippets, which is often useful.

Any time you have a block of text, such as a description of your company, or a piece of code, such as a JavaScript widget, that you want to include in multiple places, you should put it in a snippet, and then just reference the snippet each place you want to use that text or code. By using this approach, you can update the snippet at any time, and all of the places that reference it will automatically have the updated contents.

Including the contents of your snippet in your code is simplicity itself:

<w:snippet name="my-snippet-name" />

You can use snippets among your HTML code in templates, in editable regions, and even in other snippets. You can also use snippets in JavaScript, CSS, or XML files. Any time Webvanta is serving up some code, it will replace your snippet invocation with the contents of the snippet.

Sending a Parameter to a Snippet

You can also pass a parameter into a snippet by using a two-part (instead of self-closing) snippet tag. For example, if you invoke the snippet like this:

<w:snippet name="winner">George</w:snippet>

And the snippet definition is this:

<h3>The winner is <w:yield /><h3>

Then the result is the string "The winner is George". Whatever content is between the open snippet and close snippet tags is inserted in place of the <w:yield /> tag. (Unfortunately, you cannot pass more than one parameter to a snippet.)

Standard Snippets

Each SmartTheme, which provides the "seed" for a new site, comes with a variety of standard snippets that deliver commonly needed chunks of code.