uswds_paragraph_components-1.0.x-dev/templates/paragraph--uswds-card-group-flag.html.twig
templates/paragraph--uswds-card-group-flag.html.twig
{#
/**
* @file
* Default theme implementation to display a paragraph in USWDS Paragraph Components.
*
* Available variables:
* - paragraph: Full paragraph entity.
* - id: The paragraph ID.
* - bundle: The type of the paragraph, for example, "image" or "text".
* - authorid: The user ID of the paragraph author.
* - createdtime: Formatted creation date. Preprocess functions can
* reformat it by calling format_date() with the desired parameters on
* $variables['paragraph']->getCreatedTime().
* - content: All paragraph items. Use {{ content }} to print them all,
* or print a subset such as {{ content.field_example }}. Use
* {{ content|without('field_example') }} to temporarily suppress the printing
* of a given child element.
* - attributes: HTML attributes for the containing element.
* The attributes.class element may contain one or more of the following
* classes:
* - paragraphs: The current template type (also known as a "theming hook").
* - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an
* "Image" it would result in "paragraphs--type--image". Note that the machine
* name will often be in a short form of the human readable label.
* - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a
* preview would result in: "paragraphs--view-mode--preview", and
* default: "paragraphs--view-mode--default".
* - view_mode: View mode; for example, "preview" or "full".
* - logged_in: Flag for authenticated user status. Will be true when the
* current user is a logged-in member.
* - is_admin: Flag for admin user status. Will be true when the current user
* is an administrator.
*
* @see template_preprocess_paragraph()
*
* @ingroup themeable
*/
#}
{# The template default set classes. #}
{# Sets Paragraph ID as class. #}
{%
set classes = [
'paragraph',
'paragraph--type--' ~ paragraph.bundle|clean_class,
view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
'paragraph--id--' ~ paragraph.id.value,
]
%}
{{ attach_library('uswds_paragraph_components/uswds-cards') }}
{% set uswds_classes = [] %}
{% if content.field_uswds_classes %}
{% for key, class in content.field_uswds_classes if key|first != '#' %}
{% set uswds_classes = uswds_classes|merge([class['#title']]) %}
{% endfor %}
{% endif %}
{% if content.field_alternating_flags %}
{% set alternating = true %}
{% endif %}
<div{{ attributes.addClass(classes).addClass(uswds_classes) }}>
<ul class="usa-card-group">
{% for key, item in content.field_cards if key|first != '#' %}
{% set image_position = item['#paragraph'].field_image_position.value == 'right' ? ' usa-card--media-right'%}
{% set card_link = item['#paragraph'].field_make_card_link.value ? true : false %}
{% set columns = item['#paragraph'].field_number_of_columns.value ? item['#paragraph'].field_number_of_columns.value : '6' %}
{% if alternating and loop.index is odd %}
{% set image_position = ' usa-card--media-right'%}
{% elseif alternating %}
{% set image_position = '' %}
{% endif %}
<li class="tablet:grid-col{{ '-' ~ columns }} usa-card usa-card--flag{{ image_position }}">
{% if card_link %} <a href="{{ item['#paragraph'].field_button.0.url }}" class="text-no-underline card-link"> {% endif %}
<div class="usa-card__container">
<header class="usa-card__header">
<h2 class="usa-card__heading">{{ item['#paragraph'].field_card_title.value }}</h2>
</header>
<div class="usa-card__media">
{% if item['#paragraph'].field_card_image.entity.field_media_image %}
<div class="usa-card__img">
{{ item['#paragraph'].field_card_image|view }}
</div>
{% endif %}
</div>
{% if item['#paragraph'].field_text.value %}
<div class="usa-card__body">
{{ item['#paragraph'].field_text.value|raw }}
</div>
{% endif %}
{% if item['#paragraph'].field_button.uri and not card_link %}
<div class="usa-card__footer">
<a href="{{ item['#paragraph'].field_button.uri }}">
<button class="usa-button">{{ item['#paragraph'].field_button.title }}</button>
</a>
</div>
{% endif %}
</div>
{% if card_link %} </a> {% endif%}
</li>
{% endfor %}
</ul>
</div>
