On this page
Custom code (HTML/CSS/JS)
The CMS element Custom code (HTML/CSS/JS) adds your own HTML, CSS and JavaScript to a shopping experience. It is meant for people who are confident with code. For normal text, images and links, the Shopware text elements with their WYSIWYG editor are the better choice.
Caution: The code is not sanitised and is delivered exactly as you enter it. Only paste code from trusted sources and check the page before publishing.
Who may edit the element
The element is protected by its own permission. Without it you see a notice in the element and cannot change the code. An admin grants it under Settings → Users & permissions → Role → Additional permissions → "Cerberus Aspinaworld Theme", entry Shopping experiences: create and edit "Custom code" (HTML/CSS/JS).
The tabs
| Tab | Switch | Effect |
|---|---|---|
| HTML | Add HTML code | Outputs the HTML. On by default. |
| HTML | Allow placeholders | Replaces placeholders in the HTML (see below). Off by default. |
| CSS | Add CSS code | Outputs the CSS as a <style> block. Off by default. |
| JavaScript | Add JavaScript code | Outputs the JS as a <script> block. Off by default. |
| Advanced | CSS class | Extra class on the element, e.g. for your own styling. |
You can also write CSS and JavaScript straight into the HTML field; the separate tabs just keep it tidier.
Debug mode: while the theme's debug mode is on, this element's CSS and JavaScript are not output in the storefront. That makes it quick to rule out a mistake in your own code.
Placeholders
With Allow placeholders you can insert values of the current page into the HTML, for example {{ product.name }}. In the admin, clicking a placeholder inserts it at the cursor position.
| Placeholder | Value |
|---|---|
{{ entity.name }} |
Name of the page: product, else category, else landing page |
{{ product.name }} |
Product name (product pages only) |
{{ product.productNumber }} |
Product number |
{{ product.ean }} |
EAN / GTIN |
{{ product.manufacturer.name }} |
Manufacturer |
{{ category.name }} |
Category name (category page) |
{{ landingPage.name }} |
Name of the landing page |
{{ shop.name }} |
Name of the sales channel |
{{ date.year }} |
Current year |
How placeholders behave:
- Values are inserted HTML-safe, so special characters in a product name cannot break your HTML.
- No Twig is executed. Logic such as
{% if %}, comments{# #}and filters are removed. - Unknown placeholders, or ones without a value on the current page, stay empty.
{{ product.name }}on a category page gives nothing. - There is deliberately no customer data, such as the logged-in customer's name. Pages are cached, so a customer value would show up for other visitors.
Example
<p class="note">Questions about {{ product.name }}? Write to us.</p>
On the product page of an item "Beeswax candle 20 cm" this reads Questions about Beeswax candle 20 cm? Write to us.