Snippets are blocks of content that can be displayed on multiple web pages, but are updated in one place.

Snippets can help you manage content you want to re-use and share across your web pages. If you edit a snippet, all web pages that use the snippet will automatically update.

Almost any content can be saved as a snippet. If you need to make slight adjustments to snippet content, you can use variables.

See an example of a snippet

A web user can't tell if a page uses snippets. On the page above, content under 'Enterprise Agreement team' is a snippet.

Creating a snippet

Once you log in to your website:

  1. Hover over the Drupal 'Structure' menu, then go to 'Administer Snippets' > 'Add'.
  2. In the 'Administrative Title' field, add a name for your snippet. This won't appear on the published page.
  3. In the 'Administrative Description' field, add a brief summary of how to use the snippet, if required.
  4. In the 'Snippet Content' field, add the content that should appear in the snippet.
  5. Click 'Save' to finish creating your snippet.

Your snippet has now been added to a list of available snippets on your website. You can view or edit all snippets on your site by hovering over the Drupal 'Structure' menu and clicking 'Administer Snippets'.

Variables

A standard snippet has static content and will look the same across all pages it appears on.

If you need to make slight adjustments to snippet content, you can create a snippet with variables. Variables let you customise small bits of snippet content on a page.

To create a snippet with variables, follow the first four steps under 'Creating a snippet' above and then:

  1. In the 'Snippet Content' field, use curly brackets to add a variable: {variable_name}. See an example of this step.
  2. Add as many variables as you need, but replace 'variable_name' with more suitable names. Variables must use underscores instead of spaces or hyphens.
  3. Click 'Save' to finish creating your snippet with variables.
Top of page

Inserting a snippet

Go to the WYSIWYG editor where you want to add a snippet, and:

  1. Position your cursor where you would like to insert the snippet.
  2. Select the 'Insert Snippets' icon (downward pointing arrow) from the WYSIWYG editor.
  3. A 'Snippets' window will open. From the drop-down menu, select the administrative title you gave your snippet.
  4. Click 'Insert'. The snippet code will appear in the editor in square brackets.
  5. Click 'Save' to finish.

When you log in to Drupal, snippets can be identified by a dotted border. This border is only visible to web editors who are logged in.

Variables

To insert a snippet with variables, follow the first three steps under 'Inserting a snippet' above and then:

  1. At the bottom of the 'Snippets' window, your variable names will appear under 'Tokens'.
  2. Add values for each of your variables here. See an example of this step.
  3. Click 'Insert'. The snippet code will appear in the editor in square brackets, with the variable content in inverted commas.
  4. Click 'Save' to finish.
Top of page