Kosi
Kosi

Reputation: 53

Symfony 3 nested collection templating with Twig

how i can templating nested collection?.

I create templating parent collection with block:

{% block _group_match_groupMatchType_entry_row %}

In this block i have collection:

<div class="js-collection-parrent round text-right" data-prototype="{{ form_row(form.matchResult.vars.prototype)|e('html_attr') }}">

How i can get every entry row of matchResult collection which has parent collection groupMatchType?

GroupMatchType

$builder
        ->add('groupMatchType', CollectionType::class, [
            'entry_type' => MatchType::class,
            'allow_add'     => true,
            'allow_delete'  => true,
            'by_reference'  => false
        ])

MatchType

$builder
        ->add('matchResult', CollectionType::class, [
            'entry_type' => MatchResultType::class,
            'allow_add'     => true,
            'allow_delete'  => true,
            'by_reference'  => false
        ])

And view

{% block _group_match_groupMatchType_entry_row %}
   <div class="js-collection-parrent round text-right" data-prototype="{{ form_row(form.matchResult.vars.prototype)|e('html_attr') }}"></div>
{% endblock %}

I have to find name of above block (maybe like _group_match_groupMatchType_entry_row_matchResult_entry_row)

Upvotes: 1

Views: 266

Answers (2)

Kosi
Kosi

Reputation: 53

Ok i solved that. The block should be named

_group_match_groupMatchType_entry_matchResult_entry_row

Upvotes: 1

Mar&#231;al Berga
Mar&#231;al Berga

Reputation: 315

Getting all sub-elements in a form on twig is simple:

{% for element in form.elements %}
    {# Do something with this element #}
    {# But think that it will represent the form element #}
{% endfor %}

real example:

{% for movie in form.movies %}
    {{ form_widget(movie.title, {'attr' : {'class':'form-control'}}) }}
    {{ form_row(movie.id) }}
{% endfor %}

Don't really know if is what you need, but I believe it's an approach to what you mean.

Upvotes: 0

Related Questions