In Symfony2, I’m using formbuilder. I’m setting the labels in the form, as per the documentation.
However, when I’m on the ‘show’ and ‘index’ pages, I have to copy the labels into Twig.
Is there a way to have the same labels used everywhere? The options I have thought of:
- Access the formbuilder configuration, but without actually building the form
- Have a central config file, and lookup from the formbuilder and the twig files into that file
However, either way requires me to ‘do’ something, which I’m not used to in Symfony. It seems like this is something that would already have been solved, but I’m not sure how.
You can utilize translation system to overcome this problem. Make sure that you have enabled translation in
config.yml.If you have added field in your formtype like this
Create a file named
messages.en.ymlin your bundlesResources/translationsdirectory (replaceenwith your default locale and create multiple files based on the locales. Check translation chapter of the book.) and put followingAdd and edit forms label will show
Title. In index and show pages you can doThough this process is a bit lengthy but it is one time and you can change the value of the labels by changing the translation files.