Trash affects twig tweak and if drupal_view_result

Created on 24 June 2025, 12 days ago

Not really sure how to phrase or explain this, but I've found that using twig_tweak module and drupal_views_result, per the documentation , you will have a view show nodes that are in trash.

This is my twig code:

{% if drupal_view_result('publications', 'pub_by_project', node.id) is not empty %}
   <h2 class="section-heading">Publications</h2>
   {{ drupal_view('publications', 'pub_by_project', node.id) }}
{% endif %} 

...so, simply calling drupal_view_result, either in a check like here, or even in a {{ dump(drupal_view_result)}} will have the drupal_view call itself render nodes that are in trash.

If I take away the check, or other calls to drupal_view_result, the drupal_view will not render the trashed nodes. Views UI does not render the trashed nodes either.

💬 Support request
Status

Active

Version

3.0

Component

Miscellaneous

Created by

🇳🇴Norway vegardjo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @vegardjo
  • 🇷🇴Romania amateescu

    I've tried to reproduce this quickly by putting this code in a template, and the output was correct, trashed nodes were not displayed:

    {% if drupal_view_result('frontpage', 'page_1') is not empty %}
      <h2 class="section-heading">Publications</h2>
      {{ drupal_view('frontpage', 'page_1') }}
    {% endif %}
    

    Does your view have a filter on the deleted field? Because that's the only way to bypass Trash's Views query alter, see https://git.drupalcode.org/project/trash/-/blob/3.x/src/ViewsQueryAlter....

  • 🇳🇴Norway vegardjo

    Thanks for checking it out! I uninstalled Trash on this site, but I'll try to find some time to reproduce it fresh.

    It is a view of "publications", with a relation to "project, via a field on publication". Then there is a contextual filter for node.id, which is what you see in my twig code. Basically it is a view of publication nodes related to a project, shown on a project node, but where the reference is publication -> project: There are no other filters beside published and content type.

Production build 0.71.5 2024