drowl_paragraphs_bs-1.x-dev/modules/drowl_paragraphs_bs_type_button/templates/paragraph--drowl-paragraphs-bs--button.html.twig
modules/drowl_paragraphs_bs_type_button/templates/paragraph--drowl-paragraphs-bs--button.html.twig
{% extends "@drowl_paragraphs_bs/paragraph--drowl-paragraphs-bs.html.twig" %}
{#
/**
* @file
* Paragraph type "link int/ext" aka Button.
*
* % extends "paragraph.html.twig" %
* @see template_preprocess_paragraph()
*
* @ingroup themeable
*/
#}
{#
Button classes
Formatter classes are set using ui_styles.
You can add further formatters adding ui_style classes prefixed with "btn-".
#}
{%
set button_classes = [
'btn'
]
%}
{# Merge in the link attributes #}
{% set link_attributes = elements.field_link.0['#url'].options.attributes %}
{% if link_attributes %}
{% for key, value in link_attributes %}
{% if key == 'class' %}
{% set button_attributes = button_attributes.addClass(value) %}
{% else %}
{% set button_attributes = button_attributes.setAttribute(key,value) %}
{% endif %}
{% endfor %}
{% endif %}
{% set icon_position = paragraph.field_link.value.0.options.attributes['data-icon-position'] %}
{% set icon = content.field_link.0['#title'].icon %}
{% block content %}
{% apply spaceless %}
{# Hint: Requires the Micon module link formatter to work correctly! #}
<a{{ button_attributes.addClass(button_classes) }} href="{{ paragraph.field_link.0.url.toString }}">
{% if icon_position == 'before' or icon_position == 'icon_only' %}
{{ icon }}
{% endif %}
{% if icon_position != 'icon_only' %}
<span class="btn__label">{{ paragraph.field_link.value.0.title }}</span>
{% endif %}
{% if icon_position == 'after' %}
{{ icon }}
{% endif %}
</a>
{% endapply %}
{% endblock content %}
