Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
When a header (or footer) are added to a View this Twig logic, {% if header %}
, seems to always be satisfied, regardless of whether the header (or footer) should appear or not. The if I'm looking at is in views-view.html.twig.
See attached screenshots.
The extra spacing before and after the text is likely being caused by some whitespacing in the Twig template, but that is all contained within the if.
Comment | File | Size | Author |
---|---|---|---|
#26 | header_and_footer_are-2547811-26.patch | 2.65 KB | nlisgo |
#26 | interdiff-2547811-19-26.txt | 2.41 KB | nlisgo |
#19 | header_and_footer_are-2547811-19.patch | 2.64 KB | nlisgo |
#19 | interdiff-2547811-12-19.txt | 1.92 KB | nlisgo |
#19 | header_and_footer_are-2547811-19-testonly.patch | 1.92 KB | nlisgo |
Comments
Comment #2
borisson_I can't seem to reproduce this issue:
Comment #3
davidhernandezTry this to reproduce. Create a View, add a header and/or footer. Add conditions to the View so that no results are returned. You should get nothing, or empty text if configured, but should not get a header or footer div in the markup.
Comment #4
borisson_Attached patch should resolve this issue. Phpunit tests all seem to pass, let's see what the rest of the tests think.
Comment #6
borisson_Fixes the
Drupal\views_ui\Tests\PreviewTest
test and adds a new scenario that specifically tests for this (testHeaderFooterText
).Comment #8
dawehnerMh I don't get the fix. Header/footer are visible much like the empty text potentially on an empty result.
Could it be the case that the empty logic currently comes to early and so is executed in the context of the initial render step and not the final deep tree one?
(simple render array vs. the entire rendering)
Comment #9
davidhernandezYeah, the solution doesn't seem right. The header and footer should not resolve true with no content. I wonder if this is a similar problem to the region checking problem. Also, I'm wondering if there is side case where header/footer can legitimately have content when there are no rows. Maybe with no content but there are attachments or something?
Comment #10
dawehnerWell, the configuration allows you to do it.
Comment #11
davidhernandezThis is what I get when dumping the header. First when the View has no result, then with a result.
For comparison, this is what I get for the empty text.
Comment #12
davidhernandezHow about this?
Comment #13
andypost+1 to #12
Comment #15
Manuel Garcia CreditAttribution: Manuel Garcia at Appnovation commented+1 also to #12.
Comment #16
davidhernandezThat's two +1. Anyone care to rtbc?
Comment #17
joelpittetI think the solution is appropriate, or else we need to change the output of the render method on each which extends AreaPluginBase.
This does need tests though to ensure we don't break it again.
Should be able to assert that the
.view-footer
don't exist if the areas aren't used. Or create a custom template with some silly text inside those and assert it doesn't exist when that template is loaded. There is a test theme for views that may be a good candidate for that add a template toviews_test_theme
Example:
/modules/views/tests/themes/views_test_theme/templates/views-view-fields.html.twig
Comment #18
nlisgo CreditAttribution: nlisgo commentedPreparing a test
Comment #19
nlisgo CreditAttribution: nlisgo commentedComment #20
nlisgo CreditAttribution: nlisgo commentedComment #23
mansspams CreditAttribution: mansspams at Wunder commented#19 works as advertised.
Comment #24
mansspams CreditAttribution: mansspams at Wunder commented$xpath has been set on line 136 already. Should it be twice?
Comment #25
mansspams CreditAttribution: mansspams at Wunder commentedComment #26
nlisgo CreditAttribution: nlisgo commented@mansspams good spot. I have tidied up the test a bit too and added some comments.
Comment #27
dawehnerNice!
Comment #28
alexpottCommitted d997d39 and pushed to 8.0.x. Thanks!