Override field for node images to set necessary classes
This commit is contained in:
parent
a22bed986f
commit
caf80a58a5
1 changed files with 50 additions and 0 deletions
|
@ -0,0 +1,50 @@
|
|||
{#
|
||||
/**
|
||||
* @file
|
||||
* Theme override for a image fields on nodes, always a featured image.
|
||||
*
|
||||
* Available variables:
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
* - title_attributes, label, label_display: Not used; we force label_hidden.
|
||||
* - multiple: TRUE if a field can contain multiple items.
|
||||
* - items: List of all the field items. Each item contains:
|
||||
* - attributes: List of HTML attributes for each item.
|
||||
* - content: The field item's content.
|
||||
* - entity_type: The entity type to which the field belongs.
|
||||
* - field_name: The name of the field.
|
||||
* - field_type: The type of the field.
|
||||
*
|
||||
* @see template_preprocess_field()
|
||||
*/
|
||||
#}
|
||||
{# Child templates can specify classes to be added to items. #}
|
||||
{% set item_classes = item_classes ?? ['nadahuh'] %}
|
||||
{# Child templates can specify whether items should be wrapped. #}
|
||||
{% set use_item_wrapper = use_item_wrapper is defined ? use_item_wrapper : false %}
|
||||
|
||||
{% macro render_item(item, item_classes, use_item_wrapper) %}
|
||||
{%
|
||||
set item = item|merge({
|
||||
'attributes': item.attributes.addClass(item_classes)
|
||||
})
|
||||
%}
|
||||
{% if use_item_wrapper %}
|
||||
<div{{ item.attributes }}>{{ item.content }}</div>
|
||||
{% else %}
|
||||
{% import "@bulma/macros/renderables.html.twig" as renderables %}
|
||||
{{ renderables.merge_attributes(item.attributes, item, 'content') }}
|
||||
{% endif %}
|
||||
{% endmacro render_item %}
|
||||
{% import _self as helpers %}
|
||||
|
||||
{% if multiple %}
|
||||
<div{{ attributes.addClass('featured-image') }}>
|
||||
{% for item in items %}
|
||||
{{ helpers.render_item(item, item_classes, use_item_wrapper) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{% for item in items %}
|
||||
<div{{ attributes.addClass('featured-image') }}>{{ helpers.render_item(item, item_classes, use_item_wrapper) }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
Loading…
Add table
Reference in a new issue