Improve docs on accessing objects in Twig templates

Created on 14 November 2019, about 5 years ago
Updated 16 February 2023, almost 2 years ago

The comment at the top of page.html.twig (and the API docs) say that 'node' is an available variable and it contains a fully loaded node object. If you have the devel module enabled and you do {{ kint() }} in this template you get a full print-out of available variables which includes the node object and all its properties and methods.

However, doing {{ kint( node ) }} in this twig file results in a white-screen-of-death. Assuming something was broken, I was about to look into using hook_preprocess_page to set a node variable myself, but then I stumbled upon this post where someone mentions that {{ node.gettype }} should work, which turns out to be true, woop!

... so methods belonging to the node object are available but trying to run kint() on the object itself or any of its properties causes an error? I would expect this to be mentioned in one of both of the following documentation sections but I haven't seen anything -

https://www.drupal.org/docs/8/theming/twig β†’

https://api.drupal.org/api/drupal/core!modules!system!templates!page.htm...

πŸ› Bug report
Status

Closed: outdated

Version

9.5

Component
DocumentationΒ  β†’

Last updated 4 days ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom kitserve

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024