Snippets

To ease translating and changing text in templates Shopware uses snippets, which are called on by Smarty-variables in the template. So changes at the text don't consist of changes in the template.

Modifying snippets

Normal Mode

The modul to manage snippets is found under "Settings > Snippets". Opening the module displays every snippet available in all shops. To find the needed snippet, you can either use the navigation on the left side, filter by main- and subshop, empty snippets or search for their content.

After you found the correct snippet, you can alter it using the editing symbol. The choosen snippet will be highlighted and you are able to change it's content. After changing it, the update-button saves the snippet. For the changes to be visible in the storefront it is necessary to clear "Configuration + template-Cache".

Expert-Mode

Expert-Mode provides the option to delete single snippets. Also it is possible to change the Namespace ( the smarty variable). This should be used with caution, as texts in the storefront might not be displayed correct or at all after deleting a snippet or changing it's Namespace

Note: Never change the name or namespace of default snippets. This results in losing links to the template and possible template errors. Further possible errors could be crawling-errors by bots.

Creating new snippets

To create a new snippet, click on the button Add snippet (1).  A new window appears in which you can enter the data for the snippet.

The following data are required for the creation of the snippet

  • Locale: Select here the language for which the snippet is to be initially maintained. Other languages that may be available can be added after the snippet has been created.
  • Shop: Select the shop for which the snippet is to be initially maintained. Other existing shops can be added after the snippet has been created.
  • Namespace: The namespace is the area in which the snippet is to be sorted. It makes sense to store the snippet in the appropriate module, as this makes it easier to find/identify.
  • Name: Used e.g. as a variable to integrate the snippet into the template.
  • Value: Content of the snippet. Is initially maintained at this point for the language and shop selected under Locale and Shop. After the snippet has been created, the contents for other languages and shops can be added to the snippet.

Import / Export of snippets

Importing & updating of snippets

You are provided with the possibility to import new snippets or to alter existing snippets via an import. This can be done using a CSV-file. The folowing fields are necessary:

FieldnameExplanation
namespaceName of the controller
nameName of the variable
value-de_DE-1German Content
value-en_GB-1English Content

Missing snippets will be created, existing will be updated.

Before modifying snippets make sure to create a database backup! By default, you should always save the database table s_core_snippets. Third party plugins may use other tables.

Exporting snippets

Naturally it is possible to export existing snippets in various filetypes. Available for this operation are CSV (MS), CSV (delimiter) and SQL (Backup). The last one can be used to reset the snippets via SQL-statement.

Resetting of the SQL-file

If the snippets aren't displayed correctly anymore, it is possible to recreate the snippets as before the import. For this you open the SQL-file exported prior to the import and copy the SQL-statements out of the document. After this you need to open the database and insert the dump via the SQL-field. After these changes the old snippets should be there again.

Was this article helpful?