Trim the right-hand slash on namespace paths

Created on 22 June 2023, over 1 year ago
Updated 8 February 2024, 10 months ago

Problem/Motivation

It seems like #3191392: Make subdirectory path optional when using @namespace/template syntax โ†’ introduced a bug in certain scenarios.

In our project, bumping from 2.2.0 to 3.0.0-beta3 broke several pages, with errors such as:

Twig\Error\LoaderError: Template "@templates/node/node--layout--movies-hub.twig" is not defined in "sites/****/themes/custom/****/templates/node/full/node--layout--movies-hub.html.twig" at line 1. in Twig\Loader\ChainLoader->getCacheKey() (line 98 of /var/www/html/vendor/twig/twig/src/Loader/ChainLoader.php).

Twig\Environment->getTemplateClass('@templates/node/node--layout--movies-hub.twig', NULL) (Line: 204)
Drupal\Core\Template\TwigEnvironment->getTemplateClass('@templates/node/node--layout--movies-hub.twig') (Line: 381)
Twig\Environment->loadTemplate('@templates/node/node--layout--movies-hub.twig', NULL) (Line: 333)
Twig\Template->loadTemplate('@templates/node/node--layout--movies-hub.twig', 'sites/****/themes/custom/****/templates/node/full/node--layout--movies-hub.html.twig', 1) (Line: 39)
__TwigTemplate_88d77c497f448d9b8b0a12ac99839522105af94ff250d171bac18ca30c7ff718->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('sites/****/themes/custom/****/templates/node/full/node--layout--movies-hub.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Other issues seem to be reporting the same error after upgrading, such as:

๐Ÿ› Upgrade from 2.x to 3.x breaks mail templates Needs work
๐Ÿ› Upgrade to Components! 3.0.0-beta3 breaks website Active

although some of them might also include other issues due to DB updates not being run.

Steps to reproduce

I couldn't reliably reproduce the issue on a vanilla install, and need to switch to something else now. However, in a quick troubleshooting I did find that:

- If I remove the nested subdirectories from the include line in twig, things work fine. In other words, moving from:

include('@templates/node/node--layout--movies-hub.twig')

into

include('@templates/node--layout--movies-hub.twig')

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain marcoscano Barcelona, Spain

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

Comments & Activities

Production build 0.71.5 2024