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>
More on Stackoverflow Read the doc Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉
