{% spaceless %}
{#
Parameters:
- "tag" (associative array) (default: predefined structure): format:
{
type: string (default: 'link') can be 'link', 'removable', 'display'
path: string (default: '') tag url if needed),
label: string (default: '') tag text as string,
external: boolean (default: false) External icon for a tag with link
aria_label: (string) (default: '') (optional) aria label for removable tag as a string
}
- "default_icon_path" (string) Path to the icons sprite
- "extra_classes" (string) (default: '') Extra classes
- "extra_attributes" (array) (default: []): Extra attributes, format: [
{
"name" (string) (default: ''),
"value" (optional) (string)
...
]
#}
{# Internal properties #}
{% set _tag = {
type: 'link',
path: '',
label: ''
} %}
{% if tag is defined %}
{% set _tag = _tag|merge(tag) %}
{% endif %}
{% set _css_class = 'ecl-tag' %}
{% if _tag.type == 'removable' or _tag.type == 'display' %}
{% set _css_class = _css_class ~ ' ecl-tag--' ~ _tag.type %}
{% endif %}
{% set _extra_attributes = '' %}
{% set _default_icon_path = default_icon_path|default('') %}
{# Add extra class for removable tag #}
{% if _tag.type == 'removable' %}
{% if _tag.aria_label is defined and _tag.aria_label is not empty %}
{% set _extra_attributes = 'aria-label="' ~ _tag.aria_label ~ '"' %}
{% endif %}
{% endif %}
{# Internal logic - Process properties #}
{% if extra_classes is defined and extra_classes is not empty %}
{% set _css_class = _css_class ~ ' ' ~ extra_classes %}
{% endif %}
{% if extra_attributes is defined and extra_attributes is not empty and extra_attributes is iterable %}
{% for attr in extra_attributes %}
{% if attr.value is defined %}
{% set _extra_attributes = _extra_attributes ~ ' ' ~ attr.name|e('html_attr') ~ '="' ~ attr.value|e('html_attr') ~ '"' %}
{% else %}
{% set _extra_attributes = _extra_attributes ~ ' ' ~ attr.name|e('html_attr') %}
{% endif %}
{% endfor %}
{% endif %}
{# Print the result #}
{% if _tag.type == 'link' %}
{{- _tag.label -}}
{%- if _tag.external -%}
{%- include '@ecl/icon/icon.html.twig' with {
icon: {
name: 'external',
size: '2xs',
path: default_icon_path,
},
extra_classes: 'ecl-tag__icon ecl-tag__icon--external',
} only -%}
{%- endif -%}
{% elseif _tag.type == 'removable' %}
{% else %}
{{- _tag.label -}}
{% endif %}
{% endspaceless %}