ixm_blocks-1.0.x-dev/modules/ixm_blocks_statistics/templates/block--ixm-blocks-statistics.html.twig
modules/ixm_blocks_statistics/templates/block--ixm-blocks-statistics.html.twig
{#
/**
* @file
* Theme override to display a block.
*
* Available variables:
* - plugin_id: The ID of the block implementation.
* - label: The configured label of the block if visible.
* - configuration: A list of the block's configuration values.
* - label: The configured label for the block.
* - label_display: The display settings for the label.
* - provider: The module or other provider that provided this block plugin.
* - Block plugin specific settings will also be stored here.
* - content: The content of this block.
* - attributes: array of HTML attributes populated by modules, intended to
* be added to the main container tag of this template.
* - id: A valid HTML ID and guaranteed unique.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
*
* @see template_preprocess_block()
*/
#}
{%
set classes = [
'block',
'block-' ~ configuration.provider|clean_class,
'block-' ~ plugin_id|clean_class,
'ixm-stats-block',
]
%}
{{ attach_library('ixm_blocks_statistics/statistics-counter') }}
{% set statistic_id = 'statistics-' ~ configuration['block_revision_id'] %}
<div{{ attributes.addClass(classes).setAttribute('id', plugin_id|clean_class ~ configuration['block_revision_id']) }}>
{{ title_prefix }}
{% if label %}
<h3{{ title_attributes.addClass('mb-5') }}>{{ label }}</h3>
{% endif %}
{{ title_suffix }}
{% block content %}
<div id="{{ statistic_id }}">
{# ping pong items #}
{% if content.field_entity_reference_paragraph %}
<div class="row justify-content-center">
{% for key, item in content.field_entity_reference_paragraph|filter((value, key) => key|first != '#') %}
{% set safe_hash = configuration['block_revision_id'] ~ '--' ~ loop.index %}
{% set pp_attr = create_attribute() %}
{%
set pp_classes = [
'statistic-item',
'col-12',
'col-md-3',
'text-center',
]
%}
{# Setup our SVG or image style. #}
{% if item['#paragraph'].field_media_element.0.entity.image.entity.uri.value %}
{# lightning_media_image 8.x-3x source_field: [image] #}
{% set media_image = item['#paragraph'].field_media_element.0.entity.image.entity.uri.value %}
{% set image_alt = item['#paragraph'].field_media_element.0.entity.image.0.alt %}
{% elseif item['#paragraph'].field_media_element.0.entity.field_media_image.entity.uri.value %}
{# lightning_media_image 8.x-4x source_field: [field_media_image] #}
{% set media_image = item['#paragraph'].field_media_element.0.entity.field_media_image.entity.uri.value %}
{% set image_alt = item['#paragraph'].field_media_element.0.entity.field_media_image.0.alt %}
{% endif %}
{% if media_image %}
{% if '.svg' in media_image|render|render %}
{% set image = file_url(media_image) %}
{% else %}
{% set image = file_url(media_image|image_style('large')) %}
{% endif %}
{% endif %}
<div{{ pp_attr.addClass(pp_classes) }}>
{# image #}
{% if image %}
<img src="{{ image }}" alt="{{ image_alt }}" class="w-25 mb-4" role="presentation">
{% endif %}
{# content #}
{% if item['#paragraph'].field_title %}
<h3>{{ item['#paragraph'].field_title.value }}</h3>
{% endif %}
{# statistic > prefix / suffix #}
{% if item['#paragraph'].field_prefix_text or item['#paragraph'].field_number_integer or item['#paragraph'].field_suffix_text %}
<div class="row g-0 h2 text-primary">
<div class="col text-end">
{{ item['#paragraph'].field_prefix_text.value }}
</div>
<div class="col-auto statistics-count">
{# Optionally add: data-duration="" to change the count speed from the default 3000ms. #}
<span class="js-count" data-count="{{ item['#paragraph'].field_number_integer.value }}">0</span>
</div>
<div class="col text-start">
{{ item['#paragraph'].field_suffix_text.value }}
</div>
</div>
{% endif %}
{% if item['#paragraph'].field_body %}
{{ item['#paragraph'].field_body.value|raw }}
{% endif %}
{% if item['#paragraph'].field_links is not empty %}
<div class="row flex-wrap mx-n2">
{% set numTagsIndex = item['#paragraph'].field_links|length - 1 %}
{% for i in 0..numTagsIndex %}
<div class="col-auto px-2 cta-link my-2">
<a href="{{ item['#paragraph'].field_links[i].uri.toString() }}"
class="btn {{ loop.first ? 'btn-primary' : 'btn-secondary' }}">
{{ item['#paragraph'].field_links[i].title }}
</a>
</div>
{% endfor %}
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
</div>
{% endblock %}
</div>
