Getting the value of a Symfony form field inside a Twig template

Published on 2021-06-05 • Modified on 2021-06-05

In this snippet, we see how to get the value of a Symfony form field inside a Twig template. We can access it with the help of the vars property.


HTML demo of the snippet

{% trans_default_domain 'snippet' %}
<div class="row">
    <div class="col-lg-4 col-md-6 col-sm-8 ml-auto mr-auto">
        <div class="card card-login card-hidden">
            <div class="card-header card-header-primary text-center">
                <h4 class="card-title">{{ 'form_149'|trans }}</h4>
            </div>

            <div class="card-body">
                <span class="form-group">
                    <div class="input-group">
                        {{ form_label(form.login) }}
                        {{ form_widget(form.login, {'attr': {class: 'form-control'}}) }}
                        {{ form_errors(form.login) }}
                    </div>
                </span>

                <h4>{{ 'login_149'|trans }} <b>{{  form.login.vars.value }}</b></h4>
            </div>
        </div>
    </div>
</div>

 More on Stackoverflow   Read the doc  Random snippet