Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a complete list of variables that can be used in form_div_layout.html.twig?

Tags:

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?

like image 369
imikay Avatar asked Feb 28 '12 16:02

imikay


People also ask

How do you access variables in twig?

To get the variables in a document, you need to recursively "walk" through the Twig AST and have rules in place when you encounter certain types of language nodes. This class extracts variable names from Nodes if they are not always defined, and also grabs variables from the value used in ForLoopNodes and IfStatements.

What is Form_widget?

form_widget(form_view, variables)Renders the HTML widget of a given field. If you apply this to an entire form or collection of fields, each underlying form row will be rendered. Copy.


1 Answers

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 %}

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...

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.

like image 184
coma Avatar answered Jan 29 '23 08:01

coma