Support for Twig version 3

Created on 30 June 2023, over 1 year ago
Updated 13 July 2023, over 1 year ago

Summary

Drupal 10 upgraded from Twig 2 to Twig 3 and with this upgrade the syntax for the twig tag spaceless has changed. [See change record]( https://www.drupal.org/node/3256890 β†’ ).

Steps to reproduce

  • Ensure patternkit_media_library submodule is enabled
  • Attempt to add a Patternkit block outside of Layout Builder by going admin/structure/block/patternkit
  • Click Add Patternkit block
  • You should get an error message regarding the unsupported spaceless tag., See example of error below:
The website encountered an unexpected error. Please try again later.

Twig\Error\SyntaxError: Unknown "spaceless" tag. in Twig\Parser->subparse() (line 15 of modules/contrib/patternkit/templates/patternkit-add-list.html.twig).
Twig\Parser->parse(Object) (Line: 491)
Twig\Environment->parse(Object) (Line: 519)
Twig\Environment->compileSource(Object) (Line: 131)
Drupal\Core\Template\TwigEnvironment->compileSource(Object) (Line: 351)
Twig\Environment->loadTemplate('__TwigTemplate_a5cc4d6dee79c25e68d7e8a61b654484', 'modules/contrib/patternkit/templates/patternkit-add-list.html.twig') (Line: 312)
Twig\Environment->load('modules/contrib/patternkit/templates/patternkit-add-list.html.twig') (Line: 53)
twig_render_template('modules/contrib/patternkit/templates/patternkit-add-list.html.twig', Array) (Line: 372)
Drupal\Core\Theme\ThemeManager->render('patternkit_add_list', Array) (Line: 436)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
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: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 171)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Don't see the error message?

If you don't see the error above but instead receive a White Screen Of Death (WSOD), ensure you have enabled Logging and errors

  • Go to admin/config/development/logging
  • and select Errors and warnings
  • and save your changes
  • Clear caches and reload the page or try to reproduce error again

Proposed resolution

Modify modules/contrib/patternkit/templates/patternkit-add-list.html.twig as follows:

  • Replace {% spaceless %} with {% apply spaceless %}
  • Replace {% endspaceless %} with {% endapply %}
  • Clear drupal's cache
  • Repeat the steps to reproduce error and this time the error should not display and instead you will see a page with a list of links related to adding different type of Patternkit blocks

See Twig's docs for more details on the {% spaceless %} tag: https://twig.symfony.com/doc/3.x/filters/spaceless.html

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

✨ Feature request
Status

Fixed

Version

9.1

Component

Twig Support

Created by

πŸ‡ΊπŸ‡ΈUnited States mariohernandez Los Angeles

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

Comments & Activities

Production build 0.71.5 2024