简体   繁体   中英

Mix forms in twig Symfony2

I use TWIG and Symfony2. Now i want to mix forms (i need multiple forms).

The Entity Structure is: main-meal(name, date, ...), dessert(name, date, ...).

The html structure should look like this:

-> day1: form1.food1, form2.food1

-> day2: form1.food2, form2.food2

-> day3: form1.food3, form2.food3

...

form1 is the main meal form2 is the dessert

Any idea how i could do this? Here my code for ONE meal (withoud dessert - would be form2).

{% block body %}

    <h1>Neuen Essensplan eintragen</h1>
    {{ form_start(form1, {attr: {class: 'form-inline'}}) }}
        Montag:
        {{ form_widget(form1.name, { 'attr': {'class': 'foo'}, 'attr': {'placeholder': 'Hauptgericht'} }) }}
        {{ form_widget(form1.zusatzstoff, { 'attr': {'class': 'hide'} }) }}
        {{ form_widget(form1.datum.day, { 'attr': {'class': 'hdide'}, 'value':  datum[0].day  }) }}
        {{ form_widget(form1.datum.month, { 'attr': {'class': 'hdide'}, 'value':  monat  }) }}
        {{ form_widget(form1.datum.year, { 'attr': {'class': 'hdide'}, 'value':  jahr  }) }}
        {{ form_widget(form1.submit, { 'attr': {'class': 'hide'} }) }}

    {{ form_end(form1) }}

{% endblock %}

Thanks!

Yes you can use multiple forms. For what you are trying to do, look specifically into the "collection type as it will do what you want it to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM