4

I was looking at various Drupal core Twig templates to get an idea of how menus are rendered; I came across this line in menu--toolbar.html.twig.

{{ link(item.title, item.url) }}

Is link a macro? If so, where is it defined?

It doesn't appear to be a Twig feature. I couldn't find it by searching in the Drupal 8 code base.

1 Answer 1

8

It's a Twig_SimpleFunction extension, rather than a macro. It's registered with Twig in \Drupal\Core\Template\TwigExtension::getFunctions().

Its callback method is \Drupal\Core\Template\TwigExtension::getLink().

1
  • The Twig SimpleFunction link goes nowhere. 😢
    – leymannx
    Nov 12, 2022 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.