Symfony2: How To Get The Label For A Specific Form Field In Twig

If you need to render the label value for a specific field without rendering the entire HTML label element (e. g. to use it for a placeholder), you can do it by using the label form variable:

{{ form_widget(form.fieldName, {'attr': {'placeholder’: form.fieldName.vars.label}}) }}

Symfony2: How to Check If a Form Field Has Errors in Twig

Sometimes you need to check if a field or even the entire form has errors before rendering them (e.g. when adding an errors container). Here's the code snippet that allows you to check for the errors form variable:

{% if form.vars.errors or form.fieldName.vars.errors %}
{% endif %}