Pablo Ruiz Ortega
Pablo Ruiz Ortega

Reputation: 45

Getting an error while trying to access app.user on a twig templay symfony 3.4

Im trying to access to app.user.username on my twig template.

Running Symfony3.4.

My auth is working so that should not be the problem.

This is the code:

{% extends "@Foro/layout.html.twig" %}

{% block content %}

{% if is_granted('ROLE_USER') %}
    <strong>You're a normal user</strong>
{% endif %}
{% if is_granted('ROLE_ADMIN') %}
    {% app.user.username %}
    <strong>You're an admin</strong>
{% endif %}
<div class="col-lg-4">
    <h2>Identifícate</h2>
    <hr/>
    <form action="{{ path("login_check") }}" method="POST">
        <label>Email:</label>
        <input type="email" id="username" name="_username"  class="form-control" />
        <label>Contraseña:</label>
        <input type="password" id="password" name="_password"  class="form-control" />
        <br/>
        <input type="submit" value="Entrar"  class="btn btn-success" />
        <input type="hidden" name="_target_path" value="/login" />
    </form>
</div>
<div class="clearfix"></div>
{% endblock %}

I get the following error:

Unexpected "app" tag (expecting closing tag for the "if" tag defined near line 8).

Can you guys help me out?

Upvotes: 1

Views: 577

Answers (1)

t-n-y
t-n-y

Reputation: 1209

write it like that :

{{ app.user.username }}

Upvotes: 4

Related Questions