Views doesn't parse twig when there are no tokens to replace

Created on 7 March 2017, over 7 years ago
Updated 11 January 2024, 6 months ago

i have this configuration:

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

if there are results instead it is correctly printed

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

🐛 Bug report
Status

Needs work

Version

10.1

Component
Views 

Last updated 14 minutes ago

Created by

🇮🇹Italy boesbo

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • 🇺🇸United States smustgrave

    This 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

  • 🇧🇪Belgium Melodia40943

    I tried the patch on php 8.1 and drupal 9.5 but it didn't work, the {{"my text"|t }} still appears as is

  • 🇺🇸United States SocialNicheGuru

    The patch no longer applies to Drupal 9.5.9

  • 🇺🇦Ukraine itaran

    updated patch so it works with Drupal 9.5.9

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Custom Commands Failed
  • 🇬🇧United Kingdom jofitz

    Fix coding style error in patch #32.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update 12 months ago
    30,283 pass, 1 fail
  • 🇺🇸United States el1_1el

    Here'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")

  • 🇺🇦Ukraine taraskorpach Lutsk

    Just adding a re-roll of #33 for d10.1

  • last update 7 months ago
    29,630 pass, 1 fail
  • 🇮🇹Italy Giuseppe87

    I'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 :

           {% if 1 > 0 %}         hello       {% endif %}
           {{ ""|t}}
    

    Correctly replace the twig.

    However,

           {% if 1 > 0 %}  hello  {% endif %}
    

    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,

           {% if 1 > 0 %}         hello    {{ ""|t}}     {% endif %}
    

    is replaced by

        {% if 1 > 1 %} hello {% endif %} {{ ""|t}}
    

    Even if writing it in the "source code" mode of CKEditor.

    That cause a server error on the error on the view page:

    Twig\Error\SyntaxError: Unexpected character "&" in "__string_template__f605a68c7565a3509e2a3d658d6b70a7" at line 1. in Twig\Lexer->lexExpression() (line 376 of /var/www/html/vendor/twig/twig/src/Lexer.php).

Production build 0.69.0 2024