Product Snippets: Storefront Integration
Where product snippets are replaced in the storefront, the shipped templates, the Twig filter mmd_snippets and function mmd_snippet for custom templates, and notes on theme overrides
Product Snippets: Storefront Integration
Live Demo: Try this and other plugins live — no installation, no risk: demo.markus-michalski.net
Where placeholders are replaced
The plugin ships three template overrides that apply the mmd_snippets filter. Under Shopware 6.7 two of them are effective. No template changes of your own are needed.
| Location | Template | Block | Output |
|---|---|---|---|
| Description in the CMS product layout ("Product description" element of the default product layout) | storefront/component/product/description.html.twig |
component_product_description_content_text |
HTML, snippet contents sanitized |
| Product cards (listings, search, CMS product sliders and listings) | storefront/component/product/card/box-standard.html.twig |
component_product_box_description |
Text only, all HTML is stripped |
| Product detail page, legacy template | storefront/page/product-detail/description.html.twig |
page_product_detail_description_content_text |
Inactive under Shopware 6.7 |
The third template has no effect under Shopware 6.7: the Shopware core no longer has a template with this path in 6.7, it has been marked deprecated since 6.6 and is no longer loaded by default. This finding about the Shopware core comes from the source code of Shopware 6.6 and 6.7. The plugin line for Shopware 6.5/6.6 ships the same template; whether the core loads it there has not been checked here.
The replacement only applies where the filter is applied: in the product description of the CMS product layout and on product cards. It does not apply in CMS text elements, in category descriptions, in custom fields or in any other output, unless you apply the filter there yourself.
graph TD
A["Product description in the template"] --> B["Twig filter mmd_snippets"]
B --> C["Find placeholders in the text"]
C --> D["Load snippets (cache or database)"]
D --> E["Sanitize content and insert it"]
E --> F["Output in the storefront"]
What happens during replacement
- All placeholders of a description are replaced in one pass, including repeated occurrences of the same placeholder.
- The content of each snippet is sanitized with Shopware's HTML sanitizer before it is inserted. The rest of the description text stays unchanged.
- Unknown and inactive snippets, as well as snippets that have no content stored for the current language, are not replaced: the placeholder stays in the text as plain text and is visible in the shop.
- A snippet whose content exists but is empty is replaced, on the other hand: the placeholder disappears and nothing is shown.
- Replacement runs in a single pass. Placeholders inside a snippet's content are not replaced again, so snippets cannot be nested.
Twig filter |mmd_snippets
Replaces all placeholders in a string and returns HTML that is not escaped again:
{{ product.translated.description|mmd_snippets }}
A |raw is not needed. If the value passed in is empty, the result is an empty string.
Twig function mmd_snippet('identifier')
Returns the content of one active snippet in the current language, or an empty string if the snippet does not exist or is inactive:
{{ mmd_snippet('warranty-info') }}
The function only works in Twig templates, not in stored content such as product descriptions. Use the placeholder syntax there. Unlike the filter, the function does not sanitize the content, it outputs it as stored. Therefore, only let admin users you trust maintain snippets.
Custom templates and themes
If your theme overrides one of the blocks above itself, the plugin no longer replaces anything there, because the plugin template no longer produces the output. In that case apply the filter in your override:
{% sw_extends '@Storefront/storefront/component/product/description.html.twig' %}
{% block component_product_description_content_text %}
<div class="product-detail-description-text" itemprop="description">
{{ product.translated.description|mmd_snippets }}
</div>
{% endblock %}
For other content areas, apply the filter to the respective value in your own template.