Adapt pattern deprecated in Twig 2.10 for compatibility in Twig 3+

As of Twig 2.10, use the filter filter instead, or an if condition inside the for body (if your condition depends on a variable updated inside the loop and you are not using the loop variable).

Per tip on https://twig.symfony.com/doc/2.x/tags/for.html
This commit is contained in:
benjamin melançon 2022-03-06 11:45:28 -05:00
parent 9cf4362e07
commit 023119cea1
8 changed files with 22 additions and 22 deletions

View file

@ -39,8 +39,8 @@
#}
<description>
{% set one_and_done = false %}
{% for item in items if not one_and_done %}
{% if item.content['#paragraph'].type.0.entity.id == 'text' %}
{% for item in items %}
{% if item.content['#paragraph'].type.0.entity.id == 'text' and not one_and_done %}
{% set one_and_done = true %}
{{ item.content|render|escape }}
{% endif %}

View file

@ -74,8 +74,8 @@
{% set title_paragraph_index = null %}
{% set has_title_paragraph = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{% set title_paragraph_index = i %}
{{ paragraph }}
@ -103,8 +103,8 @@
<div class="container">
<div class="flow content">
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if i is not same as(title_paragraph_index) %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and i is not same as(title_paragraph_index) %}
{{ paragraph }}
{% endif %}
{% endfor %}

View file

@ -6,8 +6,8 @@
{% set has_title_paragraph = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{{ paragraph }}
{% endif %}

View file

@ -76,8 +76,8 @@
{% set title_paragraph_index = null %}
{% set has_title_paragraph = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{% set title_paragraph_index = i %}
{{ paragraph }}
@ -123,8 +123,8 @@
{% set walls_up = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if i is not same as(title_paragraph_index) %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and i is not same as(title_paragraph_index) %}
{% if paragraph['#paragraph'].field_style_escape_flow.value is not empty %}
{% set bust_out = paragraph['#paragraph'].field_style_escape_flow.value %}
{% endif %}

View file

@ -74,8 +74,8 @@
{% set title_paragraph_index = null %}
{% set has_title_paragraph = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{% set title_paragraph_index = i %}
{{ paragraph }}
@ -109,8 +109,8 @@
{% set walls_up = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if i is not same as(title_paragraph_index) %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and i is not same as(title_paragraph_index) %}
{% if paragraph['#paragraph'].field_style_escape_flow.value is not empty %}
{% set bust_out = paragraph['#paragraph'].field_style_escape_flow.value %}
{% endif %}

View file

@ -77,8 +77,8 @@ BOW! BOW BEFORE MY POWER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{% set has_title_paragraph = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{{ paragraph }}
{% endif %}

View file

@ -75,8 +75,8 @@
{% set has_title_paragraph = false %}
{% if content.field_body_paragraph %}
{% for i, paragraph in content.field_body_paragraph if i|first != '#' %}
{% if content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in content.field_body_paragraph %}
{% if i|first != '#' and content.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{{ paragraph }}
{% endif %}

View file

@ -13,8 +13,8 @@
{% set title_paragraph_index = null %}
{% set has_title_paragraph = false %}
{% if paragraphs.field_body_paragraph %}
{% for i, paragraph in paragraphs.field_body_paragraph if i|first != '#' %}
{% if paragraphs.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% for i, paragraph in paragraphs.field_body_paragraph %}
{% if i|first != '#' and paragraphs.field_body_paragraph['#items'][i].entity.type.0.entity.id == 'title' %}
{% set has_title_paragraph = true %}
{% set title_paragraph_index = i %}
<div class="column is-one-third">