tag¶
The tag macro is used to render a single tag on the page. Such tag can be rendered in a few styling variants, receive a button that allows to remove it from the page, be set as a clickable element and have some additional custom classes of choice.
Definition¶
Input parameters¶
content¶
string represents the inner text content of the tag.
options (optional)¶
object represents an object of tag configuration options
| Option key | Type | Default | Required | Description | 
|---|---|---|---|---|
| options.clickable | boolean | false | no | If set to truethe tag will be set asclickableand receive thetag_interactivestyling class | 
| options.removable | boolean | false | no | If set to truean additional button that allows to remove the tag will be displayed and the tag itself will receive thetag_interactivestyling class | 
| options.secondary | boolean | false | no | If set to truethe tag will get an additionaltag_secondarystyling class | 
| options.classNames | string | "" | no | List of classes that will be added to the tag element | 
Example¶
In this example we render a basic tag.
Example¶
In this example we render a clickable tag styled as a secondary one.
Example¶
In this example we render a removable tag with an additional class making it visible only on mobile devices.
{% from "@macros/tag.twig" import tag %}
{{ tag('My tag', {
    removable: true,
    classNames: 'visible-xs-only'
}) }}
Macro source code¶
{% macro tag(content, options = {}) %}
    {% from "@macros/icon.twig" import icon %}
    {% set interactive = options.clickable or options.removable ? "tag_interactive" : "" %}
    {% set secondary = options.secondary ? "tag_secondary" : "" %}
    <h-tag
        class="tag {{ interactive }} {{ secondary }} {{ options.classNames|join(' ') }}"
        {% if options.clickable %} clickable {% endif %}
    >
        {{ content }}
        {% if options.removable %}
            <h-tag-remove-button class="tag__remove-button"></h-tag-remove-button>
        {% endif %}
    </h-tag>
{% endmacro %}