Problem/Motivation
The following error occurs in Drupal 10.4.3 with Twig v3.19.0:
The website encountered an unexpected error. Try again later.
Twig\Error\SyntaxError: Unexpected token "name" of value "if" ("end of statement block" expected). in Twig\TokenStream->expect() (line 5 of modules/contrib/forum_access/templates/forum-access-table.html.twig).
Twig\TokenParser\ForTokenParser->parse(Object) (Line: 202)
Twig\Parser->subparse(Array) (Line: 42)
Twig\TokenParser\IfTokenParser->parse(Object) (Line: 202)
Twig\Parser->subparse(NULL, ) (Line: 95)
Twig\Parser->parse(Object) (Line: 559)
Twig\Environment->parse(Object) (Line: 590)
Twig\Environment->compileSource(Object) (Line: 131)
Drupal\Core\Template\TwigEnvironment->compileSource(Object) (Line: 409)
Twig\Environment->loadTemplate('__TwigTemplate_82e7ac16ef626a053af3fefb7f6232d9', 'modules/contrib/forum_access/templates/forum-access-table.html.twig') (Line: 371)
Twig\Environment->load('modules/contrib/forum_access/templates/forum-access-table.html.twig') (Line: 33)
twig_render_template('modules/contrib/forum_access/templates/forum-access-table.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('forum_access_table', Array) (Line: 491)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 504)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 504)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
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: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->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: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
Install the module in a Drupal 10+ installation using twig 3+ and try to edit a forum or a container.
Proposed resolution
Modify the forum-access-table.html.twig template to make it work with twig 3 by separating if clauses from for loops as for if is deprecated since Twig 2.10 (see https://twig.symfony.com/doc/2.x/deprecated.html#tags).
Remaining tasks
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comments
Comment #3
volegerUpload the static patch from MR
Comment #4
volegerWorks for Drupal ~10 setup.
Comment #5
lee56 commentedInstalled the Forum Access version 2.0.1 / ACL version 2.0.1 modules on 5/15/2025 on test site.
Had same error issues described for Drupal version 10.4.3 with 11.1.7 - Reported by "semiaddict"
Twig\Error\SyntaxError:
Unexpected token "name" of value "if" ("end of statement block" expected). in Twig\TokenStream->expect() (line 5 of modules/contrib/forum_access/templates/forum-access-table.html.twig).
Applied the patch:
forum_access-3517929-3.patch
The patch also works without any known issues for Drupal 11.1.7
Thanks to "voleger" for the patch and to "semiaddict" for reporting the issue.
Comment #6
jefflogan commentedTested. +1 from me.
Comment #7
nevergone#3517929-3: Fix Drupal ~10.0 and TWIG ~3.0 Unexpected token "name" of value "if" ("end of statement block" expected) Works well.
Comment #8
nevergoneComment #9
eelkeblokLooks like a duplicate of #3333087: Forum access table template breaks on Drupal 10. Feel free to review that and/or make changes if required.
Comment #11
nevergoneI'm not sure if this should have been closed as a duplicate, is already in RTBC status.
Comment #12
eelkeblokI guess you’re right, if this gets fixed one way or the other. I do agree it is a duplicate and the other issue has more history. Maybe that’s the problem. This one is more concise.
Comment #13
nevergone