i have this configuration:
config header
config header 2

if there are no results the view print: {{ 'News'|t }}
Error header view twig

if there are results instead it is correctly printed

(this issue don't fix this problem: https://www.drupal.org/node/2610236)

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

BOESbo created an issue. See original summary.

boesbo’s picture

Title: Views - Global: Text area (Global: Text area) if there are no results » Views - Global: Text area (Global: Text area) don't parse twig if there are no results
boesbo’s picture

Priority: Normal » Major
joshi.rohit100’s picture

I 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).

boesbo’s picture

! @joshi, so there is no way to insert strings with T?

Lendude’s picture

jonathanshaw’s picture

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

mini.addweb’s picture

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

Ivan Berezhnov’s picture

Issue tags: +CSKyiv18
hanoii’s picture

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

jonathanshaw’s picture

Agreed with #10. Always processing Twig empowers sitebuilders more, provides more consistency for developers, and makes for a simper easier-to-maintain and test codebase.

hanoii’s picture

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