Faery
Faery

Reputation: 4650

Tables and forms in Twig

I have a table-form which I implemented this way:

    <tr>
        <td>Start Date:</td>
        <td>{{ form_widget(form.start_date) }}</td>
    </tr>
    <tr>
        <td>Previous Plan:</td>
        <td>{{ form_widget(form.prev_plan) }}</td>
    </tr>

Is there a way to make this using the ready theme form_table_layout.html.twig or at all in some more flexible and elegant way?

I tried this:

    {% form_theme form 'form_table_layout.html.twig' %}
    {{ form_errors(form) }}

    {% for field in form %}
        {{ form_row(field) }}
    {% endfor %}

but it puts its own names in the left part of the table which are not the names I want. (For example instead of "Previous Plan: " in this way I got "Prev plan")

Upvotes: 0

Views: 1196

Answers (1)

Carlos Granados
Carlos Granados

Reputation: 11351

You can define your own labels when defining the form. Something like:

->add('prev_plan', 'text',array(
                'label' => 'Previous Plan'
            ))

(I don't know the field type for prev_plan, I used 'text' but if it is a different field type just change that)

Upvotes: 3

Related Questions