I would like to pass variables to twig that depend on certain routes or node types (bundles) (a user page, a comment, a page or a custom content type). I used the name of the route (entity.comment.edit_form
, entity.user.canonical
) for that purpose.
Now I need to exclude some node types (i.e. I can’t use just entity.node.canonical
for all cases, I need to create a special condition for certain types of nodes). How do I get node type (bundle?) by route name/object?
My code is in the .theme
file in HOOK_preprocess_page(&$variables)
UPD: Okay, I have discovered that there is actually $variables['node']
which contains what I need in $variables['node']->getType()
But let’s say I have just the route, how do I get an ID from it and load a node?