Goal
The big goal is to just print out the variables that are available in the twig form template /views/Form/fields.html.twig so that I can find out WHICH variables are available, AND in particular put a condition in the {% block widget_attributes %}
based on the field type (which supposedly exists but for some reason is not accessible, and other suggestions to get the type are warned against).
I just want to see all the variables that are available... and the values they hold. Easy, right?
Lost
So that led me down a lot of rabbit holes, and some helpful articles point out how you can loop through the variables of the current context:
{% block widget_attributes %}
<ol>
{% for key, value in _context %}
<li>{{ key }} :
{% if value is not iterable%}
{{ value }}
{% else %}
{{ dump(value) }}
{% endif %}
</li>
{% endfor %}
</ol>
{% set attr = attr|merge({'class': (attr.class|default('') ~ ' form-control')|trim}) %}
{{ parent() }}
{% endblock widget_attributes %}
But this doesn't print out type
, and it doesn't actually dump the value if it's not iterable. It kills symfony without any error. So getting debug to work is essential for many reasons.
Enabling Dump
All the suggestions to enable dump, don't work. Twig's website is particularly unhelpful, since it provides no context how or where to load the $twig = new Twig_Environment (and what is up with the latest version being 1.5 at twig but 1.16 in symfony?). Symfony says it will be enabled by default. But it doesn't work.
The app.php (to load the kernel has debug enabled):
$kernel = new AppKernel('dev', true);
This is what is in my config.yml:
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
And the other suggestions for enabling in the config_dev.yml don't work either:
imports:
- { resource: config.yml }
# this is from one of the suggestions, but it doesn't work and may be an older method
services:
twig.extension.debug:
class: Twig_Extension_Debug
tags: [{ name: 'twig.extension' }]
Still Lost
So as with so many thing in Symfony, it's powerful and awesome, until it doesn't work, and then there is no documentation on how to make it work. Any help would be appreciated.
I'm running Symfony 2.5, which composer updates to Twig 1.16.