问题
Is it possible to access the current template's variables from within a macro without passing the variable to the macro directly? Thanks.
回答1:
It's possible to pass all context variables to a macro:
{{ macro(_context) }}
_context
is a special variable, which contains all currently defined variables (by name => value).
来源:https://stackoverflow.com/questions/7586924/php-twig-access-current-template-variable-from-within-macro-without-passing