Using Snippets

Contents

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 new site comes with a variety of standard snippets that deliver commonly needed chunks of code. These snippets provide standard page components that are typically used in layouts:

Snippet Name Description Where Used
header Header section at the top of the page, including logo and navigation Layouts
kb_inline_search_form Search box top_nav snippet
analytics Google analytics code; account ID pulled from configuration settings Layouts
footer Page footer; includes copyright notice and links to Privacy Policy, About, and Contact Layouts

These snippets provide features for database pages:

Snippet Name Description Where Used
category_navigator Tree navigator for KB categories; requires corresponding CSS and JS links in layout Pod on KB Category and List pages
kb_item_comment_form Displays comment form Pod on KB item pages

These snippets are used automatically by the system:

Snippet Name Description Where Used
pod_frame Round-cornered pod surround; uses theme images and styling in pod.css Pods that have pod_frame adornment selected
feed_template RSS Feed template Initializes form when creating an XML feed
activation_initial New user activation message Message sent to new user when you create one
activation_reset Reset password message Message sent to user when Reset Password link is clicked
activation_thankyou Thanks you message Message sent to user when activation is successful

Comments

3 comments

Article updates

From: Michael Slater, 08/19/10

We've updated this article per your suggestions.

Note that you can use limited HTML in your comments.

If you want to include WebvantaScript or HTML that you want to display as code, you must encode the left angle bracket as < so the system does not try to interpret it.

Example snippet usage code

From: Jon Kern, 08/18/10

what markdown/textile/anything do comments support?

Example snippet usage code?

From: Jon Kern, 08/18/10

I came to this page, having just created a snippet, and was looking for some sample code to show how to insert a snippet into the page HTML.


Add Your Comments

(not published)