hsz
hsz

Reputation: 152206

Set default value of Symfony 2 form field in Twig

Is it possible to set default value of input field in Twig ?

I am rendering form row with:

{{ form_widget(form.title) }}

I want to be able to set default value like:

{{ form_widget(form.title, {data : 'Default title'}) }}

Is it even possible ?

Upvotes: 40

Views: 55447

Answers (2)

hsz
hsz

Reputation: 152206

Magic keyword for default value is value, not data.

{{ form_widget(form.title, {'value' : 'Default title'}) }}

Upvotes: 85

François Constant
François Constant

Reputation: 5496

You can do it when creating the Type as well. I think it's "cleaner" than doing it in Twig.

Upvotes: 2

Related Questions