commercetools-8.x-1.2-alpha1/modules/commercetools_demo/templates/commercetools-product-attribute-label--demo.html.twig
modules/commercetools_demo/templates/commercetools-product-attribute-label--demo.html.twig
{#
/**
* @file
*
* Demo of overriding product label attribute template.
*
* Available variables:
* - label: The attributes label.
* - key: The attributes key.
*
* @ingroup themeable
*/
#}
{% set applicable_types = ['color', 'finish'] %}
{% if key in applicable_types %}
{% set parts = label|split(':', 2) %}
{% set new_label = parts[0]|default('')|trim %}
{% set color = parts[1]|default('')|trim %}
{% set is_hex = color matches '/^#([0-9a-f]{3}|[0-9a-f]{6})$/i' %}
{% if new_label and color and (is_hex or color == 'transparent') %}
{% set swatch %}
<span
class="d-inline-block align-middle border border-dark"
style="width:1.5rem;height:1.5rem;background-color: {{ color|e('html_attr') }};"
></span>
{% endset %}
{{ swatch|raw }} {{ new_label }}
{% else %}
{{ label ? label|nl2br : '-' }}
{% endif %}
{% else %}
{{ label ? label|nl2br : '-' }}
{% endif %}
