Files
drupal-leshed/web/themes/custom/leshed/templates/field--node--field-dates--evenement.html.twig
T

63 lines
2.0 KiB
Twig
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{#
/**
* @file
* Theme override for field_dates on "evenement" nodes.
*
* Splits the daterange value into separate year/month/day parts (see
* leshed_preprocess_field() in leshed.theme) so start/end can be styled
* independently instead of relying on the default <time> rendering.
*
* Available on each item, in addition to the default `content`/`attributes`:
* - item.start_date: { year, month, month_name, day } or unset if empty.
* - item.end_date: { year, month, month_name, day } or unset if empty.
*
* @see template_preprocess_field()
* @see leshed_preprocess_field()
*
* @ingroup themeable
*/
#}
{%
set title_classes = [
label_display == 'visually_hidden' ? 'visually-hidden',
]
%}
{% macro date_parts(date) %}
<time datetime="{{ date.iso }}">
<span class="date-part date-day">{{ date.day }}</span>
<span class="date-part date-month">{{ date.month }}</span>
<span class="date-part date-year">{{ date.year }}</span>
</time>
{% endmacro %}
{% import _self as dates %}
{% if label_hidden %}
{% for item in items %}
<div{{ attributes.addClass("field-item", "digit-dates") }}>
{% if item.start_date %}
{{ dates.date_parts(item.start_date) }}
{% endif %}
{% if item.end_date and (item.end_date.year != item.start_date.year or item.end_date.day != item.start_date.day) %}
<span class="date-sep"></span>
{{ dates.date_parts(item.end_date) }}
{% endif %}
</div>
{% endfor %}
{% else %}
<div{{ attributes }}>
<div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
{% for item in items %}
<div{{ item.attributes.addClass("field-item", "field-dates") }}>
{% if item.start_date %}
{{ dates.date_parts(item.start_date) }}
{% endif %}
{% if item.end_date and (item.end_date.year != item.start_date.year or item.end_date.day != item.start_date.day) %}
<span class="date-sep"></span>
{{ dates.date_parts(item.end_date) }}
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}