Needs work
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
7 Mar 2017 at 11:13 UTC
Updated:
23 Jul 2026 at 13:55 UTC
Jump to comment: Most recent, Most recent file



Comments
Comment #2
boesbo commentedComment #3
boesbo commentedComment #4
joshi.rohit100I think there needs some discussion around what to be shown if no data as then token will have nothing to replace. Should be show as it is (no change) or just remove or return no data (empty).
Comment #5
boesbo commented! @joshi, so there is no way to insert strings with T?
Comment #6
lendudeSeems to touch on #2665766: {% %} twig syntax is only parsed in text area handler when a {{ }} token is present
Comment #7
jonathanshawAgreed. We've got 4 choices:
1) Always parse twig, but set first row as variables for twig depending on this UI "Use replacement tokens from first row" setting
2) Always parse twig, and always add the first row as variables, abandon the UI setting
3) Make a new setting additional "Process the input using Twig", and only offer the "Use replacement tokens from first row" if that is checked
4) Replace the current setting with a single "Process the input using Twig" setting
I'd suggest #2 is best - what's the point of these UI settings? Everything is presumably cached to the 11th degree, so I imagine there's no performance issue, and as long as we support Twig escaping then the twig parsing is not blocking anything a sitebuilder might want to do.
Comment #8
pranali.addweb commentedTwig syntax would only be parsed when the data is available or the token is available or present within the syntax. Please try these steps:
1.create a view and display it.
2.Should add a global filter text field to the header.
3.Replace the token with the first row. The first row as a variable should work properly.
If the data filter has nothing to replace if no data, then we should set something like no data or empty value or a message.
Comment #9
ivan berezhnov commentedComment #10
hanoiiI think this is still valid if you want to use some twig syntax on a general header, even to be shown regardless of results/no results.
Comment #11
jonathanshawAgreed with #10. Always processing Twig empowers sitebuilders more, provides more consistency for developers, and makes for a simper easier-to-maintain and test codebase.
Comment #12
hanoiiAnd also, when it says that it works "simliar to the global text on fields", there you can use twig, so that's what I was surprised when it didin't work there.
Comment #13
hanoiiI just want to comment that I kind of sorted this out by using: https://www.drupal.org/project/twig
Comment #14
Sut3kh commentedSo it looks like the inconsistency is simply due to a micro-optimisation to quick return when there are no tokens.
This actually covers more scenarios than simply having no results (such as showing 'Content' instead of 'Fields') so I have updated the title accordingly.
I would say that the expected behaviour of checking 'Use replacement tokens from the first row' is that it should always render twig (rather than render twig in certain conditions but sometimes dump the twig as plain text) so i have attached a patch to fix this 'bug'.
IMO we need Twig to be able to do things 'properly' in views, especially with no results i.e. adding a simple 'Add node' link to the header:
<a href="{{ path('node.add_page') }}">{{ 'Add Node'|t }}</a>This should probably have a simple unit test and the checkbox should be updated to explicitly state that it well render Twig as well but I'm afraid I don't have any more time for this now sorry.
I think there probably is merit in the higher level discussion around this checkbox but for now though I would call this is a simple bug in it's current state and further high-level discussion should probably go to a new issue so this can progress for now (especially as any changes to the checkbox are likely to be a breaking and therefore better suited for D9).
Comment #15
handkerchiefPatch from #14 does not work for me. Only visible change: The raw twig token is no longer displayed on the final empty view.
Comment #16
murzI have the problem with Views 8.6, when Views doesn't parse twig in header text, when View have no argument in url, if I fill argument - twig works, if remove - stops working. Is this same issue, or other?
Comment #19
jrearickI was trying to get the "Add Page" link in the header to work with the twig patterns, and it seems I ran into this issue. Applying the patch in #14 seems to have solved the issue for me.
Steps to reproduce from a fresh install of Drupal 8.9 standard profile with no nodes:
I'm not sure what's next here. I think maybe running the existing tests to make sure it doesn't cause regressions and developing tests for this issue? Neither of which I am familiar with how to do.
Comment #20
jrearickNeeds Reivew to run the patch through current tests.
Comment #21
mistrae commentedTested on 9.1.8, the twig in header/footer is not parsed (my view displays teasers)
Comment #22
nikathonePatch #14 works for me when adding the "Global: Unfiltered text" under "NO RESULTS BEHAVIOR".
Comment #25
el1_1el commented#14 works for me in both header and no results behavior using unfiltered text with fields or teasers in 9.3.14 with the following twig that does require the twig tweak module
Setting back to needs review since it looks like this has been an issue for a while
Comment #27
bwong commented#14 works for me in header, footer and no results using unfiltered text with fields in 9.3.14.
What I found odd is that I need to have a substitution that works before full twig works. Otherwise I wind up with the unevaluated twig expression. This could be an issue with twig substitution rather than the this patch.
Comment #29
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
#14 didn't work for me on Drupal 10.1
Added a test area to a view
Added {{ 'fail'|trans }} to the text area
Would expect to see nothing but renders like I do if I place the same code in a twig template.
Also was previously tagged for tests so that will still need to happen as well
Comment #30
melodia40943 commentedI tried the patch on php 8.1 and drupal 9.5 but it didn't work, the {{"my text"|t }} still appears as is
Comment #31
socialnicheguru commentedThe patch no longer applies to Drupal 9.5.9
Comment #32
itaran commentedupdated patch so it works with Drupal 9.5.9
Comment #33
jofitzFix coding style error in patch #32.
Comment #34
el1_1el commentedHere's a patch for 10.1.3 - yes it has coding style errors (its not going to be committed w/o tests anyway so ¯\_(ツ)_/¯ ).
Patch is designed to show that running $text through Xss::filterAdmin when the $tokens var is empty is what causes the issue. I may be totally mistaken or misunderstanding something, but the $build runs the xss filter anyway at
return Xss::filterAdmin($children);, so I'm not entirely clear why showing raw twig to users when results are empty is necessary but again ¯\_(ツ)_/¯And moreover - patch is to allow people who have this issue to update to 10.1.x without showing twig syntax to users (ie what my PM/UX manager referred to as "cool gobbly gook")
Comment #35
taraskorpachJust adding a re-roll of #33 for d10.1
Comment #36
giuseppe87 commentedI've tried the patch on D10.1.x but it seems it has some problems:
If I print in the view header using unfiltered text :
Correctly replace the twig.
However,
Does not replace the twig.
What's more, if I use the Global Text Area, and thus a input area with a text format and CKEditor,
is replaced by
Even if writing it in the "source code" mode of CKEditor (the > is html escaped).
That cause a server error on the error on the view page:
Comment #38
freelockUpdated patch for 10.3.0.
Comment #39
aporieReroll for 10.3. I think we got lost in the rerolls, #38 didn't work for me.
Agree with #34.
Also, have removed unnecessary checks on parameter
$tokenswhich would never be undefined and just wait to be typed into array IMO.Let's see if that passes the tests, but from a quick look, I haven't seen any tests regarding parsing of tokens or twig templates. So, we might need a bunch of more tests, to test every area for token parsing when "Use replacement tokens from the first row" is ticked or not.
Currently, only empty area is checked for global tokens in
core/modules/views/tests/src/Functional/Handler/AreaTest.php:testRenderAreaToken, but I might be missing other tests I haven't seen.Also guys, I'd like to point/question the necessity of using string translations (such as {{ 'My text'|t }}) in views as they should be translated using entity translation? In my case, I need it to parse twig.
Comment #40
athul dinesh commentedI attempted to apply the patch mentioned in comments #38 and #39 on Drupal core version 10.3.0, but unfortunately, it did not work. It seems that the patch is not compatible with this version. Could you please provide an updated patch that is compatible with Drupal 10.3.0?
Comment #41
taraskorpach#39 has worked for me
Comment #44
bwong commentedI was also able to get #33 working on Drupal 10 manually patching and #39 to work with Drupal 11. Only Drupal 11 has renderInIsolation() so #39 will not work on Drupal 10.
Comment #45
manibharathi ezhimalai ravi commentedHi,
MR !8815 has been verified successfully in the Drupal 11.x version. Since all the testcases are passed. Nothing to be update for the functionality.
Let me know incase of anything need to be update.
Before Patch:

After Patch:

Comment #46
pacproduct commentedPatch in MR !8815 works for us too, on Drupal
11.1.6.Thanks a lot!
Comment #47
ressaJust leaving a note, in case someone else also who simply want to translate a string finds this issue. Because without the patch, in a view which has results, in order to get Twig to render a string in a "Global: Text area" in the "Header" section in Drupal 10, I need to enable "Use replacement tokens from the first row" and only then is a string such as
{{ ('My string.'|trans) }}translated.Comment #48
siramsay commentedThe patch from https://git.drupalcode.org/project/drupal/-/merge_requests/8815/diffs applies to Drupal 11.2.4.
I downloaded the patch 8815.patch from the code dropdown and applied it using composer patches
Comment #49
siramsay commentedMaybe still needs work? If so, please change back.
re:
Merge request pipeline #549193 failedComment #50
smustgrave commentedStill needs test coverage
Comment #52
dhavalpanchal commentedThe changes have been added as a patch file which are implemented in merge request 8815. The changes are working correctly on Drupal 11.3.
Comment #53
remi-simaer commentedI've tested the patch from MR !8815, and it works well on Drupal 11.3.13. Thanks!