Replace TWIG render with is not empty checks

Created on 22 December 2021, almost 3 years ago
Updated 17 April 2024, 7 months ago

Problem/Motivation

Currently the Bootstrap Paragraphs use a lot of TWIG render to identify if a field has content or not. This could be simplified by using is not empty checks in TWIG templates.

Steps to reproduce

Proposed resolution

Replace TWIG |render with is not empty checks based on paragraph entity instead of content render object.

Current code with TWIG render based on content render object:

{% set background_field = content.bp_background|render %}
{% if background_field %}
  {% set classes = classes|merge(column_style_2_classes) %}
{% endif %}

Refactored with TWIG is empty check based on paragraph entity:

{% if paragraph.bp_column_style_2 is not empty %}
  {% set classes = classes|merge(column_style_2_classes) %}
{% endif %}
  • Improve performance because fields are not rendered twice or more during TWIG templating.
  • Cleaner code structure.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024