PHP Twig:从宏内部访问当前模板变量而不传递? [英] PHP Twig: access current template variable from within macro without passing?

查看:32
本文介绍了PHP Twig:从宏内部访问当前模板变量而不传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从宏中访问当前模板的变量而不直接将变量传递给宏?谢谢.

Is it possible to access the current template's variables from within a macro without passing the variable to the macro directly? Thanks.

推荐答案

可以将所有上下文变量传递给宏:

It's possible to pass all context variables to a macro:

{{ macro(_context) }}

_context 是一个特殊变量,其中包含所有当前定义的变量(按名称 => 值).

_context is a special variable, which contains all currently defined variables (by name => value).

这篇关于PHP Twig:从宏内部访问当前模板变量而不传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆