1
votes

Here's the main form layout twig file:

https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

An example:

{% block form_widget_simple %}
{% spaceless %}
    {% set type = type|default('text') %}
    <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{% endblock form_widget_simple %}

I wonder where varaibles like "type" or "value" come from?

The goal I'm trying to achieve is to set form row's label as a placeholder in the widget. How can I accomplish this?

1

1 Answers

0
votes

Details how to override Template for Form field you will find here.

If you trying to change labels to placeholders all you need is to change way of rendering your forms. Remove form_widget(form) and switch to render every separate form field:

{# ... #}
<div class="form-group">
    {{ form_errors(form.email) }}
    {{ form_widget(form.email, {'attr': {'class': 'form-control', 'placeholder': 'E-mail address'|trans }}) }}
</div>
{# ... #}

This example generate input for email field and html/css classes for bootstrap. And shows you how {{ type }} and {{ value }} are passed - by attr array.

Good Luck!