是否有可以在 form_div_layout.html.twig 中使用的变量的完整列表? [英] Is there a complete list of variables that can be used in form_div_layout.html.twig?
问题描述
我想获取Symfony表单主题文件form_div_layout.html.twig中所有可用的变量,我阅读了Symfony官方文档并在网上搜索,但找不到任何有用的信息,有人可以帮助我?
I want to get all the variables available in the Symfony form theme file form_div_layout.html.twig, I read the Symfony official documention and searched on the web, but couldn't find any useful information on this, can someone help me?
推荐答案
好吧,你可以通过迭代上下文来获取每个块中所有可用的变量:
Well, you can get all the available variables in each block by iterating the context:
{% block form_widget_simple %}
<ol>
{% for key, value in _context %}
<li>{{ key }}</li>
{% endfor %}
</ol>
{% spaceless %}
{% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{% endblock form_widget_simple %}
如果你想使用你的,那么你必须覆盖实际呈现这些小部件的类,只需看看 AbtractType::buildView...
And if you want to use yours, then you'll have to overwrite the classes that actually are rendering those widgets, just take a look at AbtractType::buildView...
正如@Gregoire 所建议的,您可以使用 1.5 版中的 {{ dump(_context) }}
(http://twig.sensiolabs.org/doc/functions/dump.html),但请注意它会打印大量信息.
As @Gregoire suggested, you can use {{ dump(_context) }}
from version 1.5 (http://twig.sensiolabs.org/doc/functions/dump.html), but be aware that it will print a big amount of info.
这篇关于是否有可以在 form_div_layout.html.twig 中使用的变量的完整列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!