Snippets

Content placeholders in Joomla!

  • Last updated: 21 Apr 2020
  • Version: 6.7.0
  • Types: Component System plugin Editor button plugin
  • Joomla rating: 100%

Tutorial for Snippets

There is a Free and a Pro version of Snippets.
The parts in this tutorial that only concern the Pro version will be marked with: Pro only

Introduction

Snippets is a Joomla! administrator component (combined with a system plugin and a editor button).

With Snippets, you can create reusable snippets (pieces of text/content), and easily include them into your content via a simple tag, like:

{snippet my-first-snippet}

When you edit the article (or module, or wherever you put the snippet tag), you will still see the tag. But on frontend view, you will see the content of the snippet instead.

Have a text snippet or a sentence you use often? Prepare it once, then simply insert it in articles with one click.

The great thing about Snippets is that when you change the content of a snippet, the output changes automatically in every place where you have used the tag!


Note: If instead you're looking for a solution where a certain text snippet is actually permanently inserted in the article content, you can use Content Templater instead.

With Snippets you can replace the dynamic tag with a piece of content made with the standard content editor. If you need more advanced control in your replacements you can use ReReplacer, which allows you to enter raw code, make custom plugin tags, use PHP and much more.

Creating a Snippet

Once Snippets is installed, you will be able to access it via the Regular Labs - Snippets menu link under Components. This brings you to the component view, which lists all the snippets you created.

To create a Snippet, simply create a new item. You will be presented with the Snippet edit screen, which features a simple content editor:

Creating a Snippet

The first thing you you want to do is give the Snippet a Title (for you own reference) and a Snippet ID. The Snippet ID is very important because is the alias for the snippet that you're going to use in your {snippet} tag later.

To make a text snippet, you can then simply place your desired content into the editor field. This can be any content you want, with any styling, formatted however you want, just like when you are used to.

Once you're happy with your Snippet, simply save it, and this part is done!

Settings

When creating or editing a Snippet, on the right side you also have some options at your disposal. See the Item Settings section for more details.

You find a Description field, where you can optionally add a note to describe what you're using the snippet for. You can assign snippets to simple Categories.

And you can set a few extra settings. For example, the "Remove Paragraph Tags" option allows you to remove paragraph inside the content of a Snippet, which is useful when you want to use the snippet inline (inside sentences).

With the Pro version, you can also decide whether you want to show the Snippet in the select list when the Snippets Editor Button is clicked.

You can control these settings at a global level as well, see Configuration Settings section for more details

Inserting a Snippet

You can place a Snippet by using the snippet tag directly into your content. The syntax is very simple, it looks like:

{snippet snippet-id}

So to place a snippet you have given the "Snippet ID" copyright', you can simply place:

{snippet copyright}

When you edit the article (or module, or wherever you put the snippet tag), you will still see the tag. But on frontend view, you will see the content of the snippet instead.

If at any time you want to change the content of the Snippet, simply change it in the Snippet itself that you created earlier, and the output will change automatically in every place where you have used the tag.

Editor Button Pro only

You can enter the tags directly into your content. However, to save time typing and remembering what the exact syntax is, the Pro version of Snippets comes with a handy editor button.

You can use this editor button (located below the text input area) to place a {snippet} tag into your article (or other editor fields).

You can customize the default tag settings in the Global Configuration Settings.

Using Dynamic Snippets

You can pass to the {snippet} tag some "variables" that can make your snippet more dynamic.

This allows you to use one snippet that will generate a different output depending on what you pass along in the tag.

Then in the text of the Snippet, you can put placeholders for those variables with \1, \2, etc.

So in the copyright example, your Snippet text could look like:

©\2 - \1 - All rights reserved

And you can pass along the two variables the tag like this:

{snippet copyright|My Company|2020}

This would result in:

©2020 - My Company - All rights reserved

While with this tag:

{snippet copyright|Another Company|2019}

You would get:

©2019 - Another Company - All rights reserved

Item Settings

Here are the Item Settings you can find when creating and setting up a snippet.

Title Give the snippet a name.
Snippet ID Give the snippet an id. This id is used in the {snippet} tag.
Status You can use this to (temporarily) disable this item.
Description Give the item a short description telling you what it actually does. Everything following '---' will not be displayed in the list view.
Category Select or create a category to be displayed.
Remove Paragraph Tags

Select to remove paragraph tags inside the snippet. Surrounding tags will be removed. Paragraph tags inside the content will be replaced with double breaks.

This option can be used when you want to use the snippet inline (inside sentences), where paragraph tags would create issue.

Place HTML comments By default HTML comments are placed around the output of this extension.
These comments can help you troubleshoot when you don't get the output you expect.
If you prefer to not have these comments in your HTML output, turn this option off.
Enable in html head Select to make the Snippet tags also get replaced inside the head part of the html output.
Show in Editor Button List Select whether to show the Snippet in the select list when the Snippets editor button is clicked

Configuration Settings

From the Snippets component view, in the toolbar on the right, you will see the "Options" button.

When you click on that, you will be directed to the Global Configuration options for Snippets.

Here is an overview of the global configuration settings. All descriptions are available in the tooltips of the options.

Editor Button Options Pro only

Enable in frontend If enabled, it will also be available in the frontend.
Button Text This text will be shown in the Editor Button.

Other Settings

Snippet tag The word to be used in the tag.
Note: If you change this, all existing tags will not work anymore.
Tag Characters The surrounding characters of the tag syntax.
Note: If you change this, all existing tags will not work anymore.
Options: {...}, [...], {{...}}, [[...]], [:...:], [%...%]
Remove Paragraph Tags

Select to remove paragraph tags inside the snippet. Surrounding tags will be removed. Paragraph tags inside the content will be replaced with double breaks.

This option can be used when you want to use the snippet inline (inside sentences), where paragraph tags would create issue.

Strip Surrounding Tags Select to always remove html tags (div, p, span) surrounding the plugin tag. If switched off, the plugin will try to remove tags that break the html structure (like p inside p tags).
Disable on Components Select in which frontend components NOT to enable the use of this extension.
Remove in Disabled Components If selected, the plugin syntax will get removed from the component. If not, the original plugins syntax will remain intact.
Enable in html head Select to make the Snippet tags also get replaced inside the head part of the html output.
Fix HTML

Select to let the extension fix any html structure issues it finds. This is often necessary to deal with surrounding html tags.

Only switch this off if you have issues with this.

Place HTML comments By default HTML comments are placed around the output of this extension.
These comments can help you troubleshoot when you don't get the output you expect.
If you prefer to not have these comments in your HTML output, turn this option off.
Show Update Notification If selected, an update notification will be shown in the main component view when there is a new version for this extension.
Show Copyright If selected, extra copyright info will be displayed in the admin views. Regular Labs - extensions never show copyright info or backlinks on the frontend.

User Actions Log

Log User Actions Select to store User Actions. These actions will be visible in the User Actions Log module.
Events To Log Select the actions to include in the User Actions Log.

Permissions

The Joomla permission settings control access to the different actions for each user group. For more information on how these permissions work, see the Joomla docs: Access Control List Tutorial: Component Options & Permission

Installation

You can either install Snippets by using the core extension manager available in the Joomla! Administrator Control Panel, or by using the powerful Regular Labs Extension Manager.

Note: When updating Snippets, you do not need to uninstall it first. The package will update all the files automatically.

Keep in mind that when you update to a major new version (or uninstall first), you might lose some configuration settings.

Regular Labs Extension Manager

It is very easy to install/update any Regular Labs Extension using the Regular Labs Extension Manager.

Please see the Tutorial for the Regular Labs Extension Manager for more detailed information...

Joomla! Extension Manager

To install via the Joomla! Extension Manager, just follow these steps:

  1. Log into your Joomla administrator;
  2. In the menu, choose: Extensions >> Extensions;
  3. Choose the tab: Install from Web (or enable it if you haven't done so yet);
  4. Select the search field and enter Snippets and hit enter;
  5. Click on the Snippets listing;
  6. Click on Install;
  7. Click on Install to confirm.
Joomla! Installer - Install from Web

Or if you need to install the Pro version or cannot install via the 'Install via Web' method for some reason:

  1. Download the extension install file (.zip);
  2. Log into your Joomla administrator;
  3. In the menu, choose: Extensions >> Extensions;
  4. Choose the tab: Upload Package File;
  5. Click on the Choose File button and select the extension zip;
  6. Click on Upload & Install.
Joomla! Installer - Upload Package File

If you have problems installing Snippets, please try the manual installation process as described here: docs.joomla.org/Installing_an_extension