tamilselvancst
tamilselvancst

Reputation: 488

twig print field multiple image in field templates

Here, I have attached my code

<div{{ attributes }}>
    {% if not label_hidden %}
        <div{{ title_attributes.addClass('field-label') }}>{{ label }}</div>

    {% endif %}
    <div{{ content_attributes.addClass('gall-wrp') }}>
        {% for item in items %}

  <a class="gall-img" href="{{ file_url(element['#object'].field_multiple_image.0.entity.uri.value) }}"> 
       <img src="{{ file_url(element['#object'].field_multiple_image.0.entity.uri.value) }}"></a>

        {% endfor %}
    </div>
</div>

How to change {{ file_url(element['#object'].field_multiple_image.0.entity.uri.value) }} dynamically change value of 0.

Upvotes: 0

Views: 928

Answers (2)

tamilselvancst
tamilselvancst

Reputation: 488

Here, I have fixed this,

<div{{ attributes }}>
    {% if not label_hidden %}
        <div{{ title_attributes.addClass('field-label') }}>{{ label }}</div>      
    {% endif %}
    <div{{ content_attributes.addClass('gall-wrp') }}>
        {% for item in element['#object'].field_multiple_image %}      
          <a class="gall-img" href="{{ file_url(item.entity.uri.value) }}"> 
          <img src="{{ file_url(item.entity.uri.value) }}"></a>              
        {% endfor %}
    </div>
</div>

Upvotes: 0

goto
goto

Reputation: 8162

.0 is the same than [0]. You can use:

{{ file_url(element['#object'].field_multiple_image.[yourVar].entity.uri.value) }}

Upvotes: 1

Related Questions