symfony - Symfony2 Twig Form Widget Array Access -


i have form widget several choices (many-to-many relationship) in twig template can iterate on checkboxes:

  {% choice in form.downloads %}             {{ form_widget(choice) }} {{ form_label(choice) }}<br />   {% endfor %} 

i'd acces choices directly (they should bi formatted end positioned differently) tried several syntaxes doesn't work

{{ form_widget(form.downloads.0) }} {{ form_label(form.downloads.0) }}<br /> {{ form_widget(form.downloads['0']) }} {{ form_label(form.downloads['0']) }}<br /> {{ form_widget(form.downloads[0]) }} {{ form_label(form.downloads[0]) }}<br /> 

do use wrong array keys or array access not possible?

array access possible when you're using twig. guess error got when you're trying access first generated checkbox using

{{ form_widget(form.downloads.0) }} {{ form_label(form.downloads.0) }}<br /> 

is

method "0" object "symfony\component\form\formview" not exist in ... 

so, you've use child name of checkbox. should have in buildform like:

 $builder->add('childname', 'anytypeyouwant', array()) 

but guess you're using collection type generate checkboxes. in specific case

{{ form_widget(form.downloads.0) }} {{ form_label(form.downloads.0) }}<br /> 

should work fine! used access specific collection fields without customized keys.

you should use twig debug extension check form.downloads

{% debug form.downloads %} 

and if debug doesn't work, you've add in "app/config/config.yml" file

services:     debug.twig.extension:         class: twig_extensions_extension_debug         tags: [{ name: 'twig.extension' }] 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -