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
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | bootstrap_paragraphs-replace_twig_render_not_empty_checks-3255663-5-2.0-beta8.patch | 27.96 KB | it-cru |
Issue fork bootstrap_paragraphs-3255663
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
it-cruComment #4
twills commentedNot able to apply patch successfully.
Comment #5
it-cruAdded current state of MR as patch against 8.x-2.0-beta8 release before rebase.
Comment #6
it-cru@twills: Diff of MR should apply again with 8.x-2.x-dev.
@thejimbirch @kerrymick: Is this change already addressed in development of 5.0.x branch?
Comment #7
it-cruComment #10
kerrymick commentedThanks for the fix @IT-Cru! This does need to be fixed in the 5.0 branch. I will make an issue for that.
Comment #11
kerrymick commentedComment #12
kerrymick commentedComment #13
b.friddy commentedThere's one if check in the paragraph--bp-modal.html.twig on line 182 that is mispelled (stating 'it' instead of 'is')
{% if paragraph.bp_modal_footer it not empty %}
vs
{% if paragraph.bp_modal_footer is not empty %}
Just wondering if this could be updated (I believe I saw a similar statement in the 5.0.0 version as well)
Comment #14
it-cruIn MR to 5.0.x I can't find this issue. So it seems to be only related to 8.x-2.x branch.
If this is already included in latest release, I think it would be good to create a new issue as critical bug, because of this typo TWIG modal template is broken.