Snippets
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.
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:
- Hover over the Drupal 'Structure' menu, then go to 'Administer Snippets' > 'Add'.
- In the 'Administrative Title' field, add a name for your snippet. This won't appear on the published page.
- In the 'Administrative Description' field, add a brief summary of how to use the snippet, if required.
- In the 'Snippet Content' field, add the content that should appear in the snippet.
- 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:
- In the 'Snippet Content' field, use curly brackets to add a variable: {variable_name}. See an example of this step.
- Add as many variables as you need, but replace 'variable_name' with more suitable names. Variables must use underscores instead of spaces or hyphens.
- Click 'Save' to finish creating your snippet with variables.
Inserting a snippet
Go to the WYSIWYG editor where you want to add a snippet, and:
- Position your cursor where you would like to insert the snippet.
- Select the 'Insert Snippets' icon (downward pointing arrow) from the WYSIWYG editor.
- A 'Snippets' window will open. From the drop-down menu, select the administrative title you gave your snippet.
- Click 'Insert'. The snippet code will appear in the editor in square brackets.
- 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:
- At the bottom of the 'Snippets' window, your variable names will appear under 'Tokens'.
- Add values for each of your variables here. See an example of this step.
- Click 'Insert'. The snippet code will appear in the editor in square brackets, with the variable content in inverted commas.
- Click 'Save' to finish.