Getting the id of a Symfony form inside a Twig template
Published on 2022-08-06 • Modified on 2022-08-06
This snippet shows how to get the id of a Symfony form inside a Twig template. This is useful when wanting to give a particular attribute for a submit button, for example. Indeed, we don't want to use a raw value, but we concatenate the form's id with an extra string.
form.var.id: <b>{{ form.vars.id }}</b>
<br/>
<button type="submit" id="{{ form.vars.id }}_button_submit">My submit button id's: {{ form.vars.id }}_button_submit</button>
HTML demo of the snippet
form.var.id: account_create
More on Stackoverflow Read the doc Random snippet