You are currently viewing the article on an older Shopware version!

Snippets

Overview

Shopware uses snippets for the translation and customization of texts, which can be managed at this point. For example these snippets can be output in the frontend.

The snippets are divided into snippet-sets. In the standard system, there are the sets BASE de_DE (1) and BASE en_GB (2). They include the translations for German and English. They use the respective base files messages.de_DE and messages.en_GB. These base files include the standard values of the snippet-sets to be able to reset the snippets later, for example.

Don't edit these files manually, because they help you to reset the snippets to a basic value.

With the button Edit snippets (3) you can edit the previously selected snippets set and the included text modules.
With the button Add snippet-set (4) you create a new snippet-set. You can create this either based on a base file or by using the arrow next to the button as a duplicate of an already existing set.
The context menu (5) allows you to edit, duplicate or delete a snippet-set. 
 

Edit Snippet

To edit a snippet, click on the respective set in which the snippet is located. If you want to edit a snippet in several sets you can also select these sets by the checkboxes and click on the Edit snippets button.

Now you can see a with all snippets that are stored in the database table snippets. In the column Name (1) you will find the name of the snippets.  Each snippet has a translation in each snippet-set (2)
With the context menu (3) you can edit the snippets for the respective variable or reset it to the default value from the base file.
On the right side you will find the Refresh button (4). This button compares or updates the data with the database table snippets.
With the button Filter (5) you can show some filter options for the displayed snippets.

Edit

When you click on edit in the context menu, you open the edit option.  
Here you can see the name of the variable. Under the item Translations you can edit the content of all translations of this snippet.

Filter

In the filter menu you can define various filters to make the display of the text modules on a clear way. 

Show empty snippets only (1): This filter only displays snippets that have no content.  
Show custom snippets (2): This filter only displays snippets which have been created by an admin. So this snippets are not part of the base file. 
Author (3): With this filter all snippets of a certain author can be found. The standard snippets from the base file have the author Shopware here. 
More filters (4): This filter helps you to filter the snippets by function. Snippets from the Checkout area can be filtered with the checkout filter, for example. 

Creating a new snippet

If you need an additional snippet, you can create a new snippet within an snippet set. New snippets are created globally. Therefore, you do not need to create every snippet individually. You can then maintain the contents of the snippet for all snippet sets.

To create a new snippet, first switch to a snippet set. This is possible by either clicking directly on the name (1) of the set or by opening the context menu by clicking the "..." button (2).

In the snippet set you can then use the button New Snippet (1) to open the mask for creating a new snippet.

At first assign a Name (1) for the new snippet. Since the name is also used for the integration, for example, in the frontend, we recommend that you do not use spaces or special characters. You should also choose a meaningful name.
You can now define the contents of the snippet. In the area Translations (2), a separate field is displayed for each existing text module set.

The new snippet can only be saved (3) if you have given it a valid name.

In this tutorial you will learn how to display the snippet in the frontend.

Creating a new snippet set

If you want to use snippet in a sales channel that differs from the standard, you can solve this by using your own snippet set. This is especially useful if you want to use the standard set unchanged, e.g. if you want to use different snippet sets in a sales channel with different URLs for England and Ireland.

You have two options for creating a new snippet set. Based on one of the base files (German and English are included in the standard version) you can create a new set by clicking the button Add snippet Set (1). Alternatively, you can duplicate an already existing set, this is also possible for sets you have created yourself. To do so, either open the drop down menu (2) next to the Add button or the context menu of a Snippet Set by clicking the "..." button (3).

Add

After you have clicked on the button Add snippet set, a mask appears directly in the overview where you can enter the relevant information.

Now assign a name for the set and select the base file that will be used as the foundation. By assigning the base file, its snippets are used as fallback for the new set. As long as you don't add your own content to the snippet in the new set, the values from the base file will be used.

Duplicate

When duplicating you can choose from all existing sets. The duplicate is created directly with the same name and the addition copy. You can change the name later on in the overview. To do this, double-click on the line of the snippet set whose name you want to change. Please note that if you click on the name of the set, you will be taken to the overview of the contained snippets and the name cannot be changed there.

Tips and tricks

If you want to use a link in a text module, you can do this using the HTML attribute a href.


<a href="URL">displayed text</a>

This then looks for example as follows.


<a href="https://www.shopware.com">Call the Shopware homepage</a>

Edit Service hotline

You can change the content of the service hotline by editing the footer.serviceHotline snippet. By default, the service hotline is displayed in the footer on the storefront. If you want to edit areas of the footer, such as new links or navigation points, see the tutorial Setting footer and service menu.

To edit the service hotline content, go to Settings > Snippets, select the appropriate snippet set and search for footer.serviceHotline. When you open the snippet, you can change the text in the desired language under Translations. Then click on Save.

Insert line breaks

If you want to insert a line break within a text module, you can do this using the HTML attribute br.


After the comma,<br> there is a line break.

Was this article helpful?