Wrong usage of if not empty in TWIG files

Created on 15 May 2024, 7 months ago
Updated 15 September 2024, 3 months ago

Problem/Motivation

Adapting πŸ› Replace TWIG render with is not empty checks Fixed for 5.0.x went a little bit wrong because it looks like all if not empty checks are based on content instead of paragraph object in TWIG files.

Example from templates/paragraph--default.html.twig

{# Prints div with classes, and content without Width and Background. #}
	<div{{attributes.addClass(classes)}}>
		<div class="paragraph__column"> {% if content.bp_header is not empty %}
			<h2>{{ content.bp_header }}</h2>
		{% endif %}
		{{ content|without('bp_background', 'bp_header', 'bp_width', 'bp_margin', 'bp_padding') }}
	</div>
</div>

The content objects always include some information for rendering so this if not empty check doesn't work properly and for example empty H2 tags for content.bp_header gets rendered when there is not data in bp_header field of this paragraph.

Steps to reproduce

Create a simple BP paragraph without filling out header field and check rendered paragraph for empty h2-tag from this created paragraph.

Proposed resolution

Replace all TWIG {% if content.<bp_field> is not empty %} check with {% if paragraph.<bp_field> is not empty %} and also check if they could be simplified without accessing stuff like bp_accordion_expand['#items'].getString() in TWIG if statement.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany IT-Cru Munich

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024