Accessing grav.user.Level?

In a user’s *.yaml file (in user/accounts) I notice the “Level:” property defaults to “Visitor” when someone registers on the frontend using root/user_register/ (the login plugin route). Of course, this can be changed to something else like “Member” in Admin.

What I am trying to do is write a little twig logic into the body of a default page based on this “Level” property attached to the current (logged in) user.

Twig has no problem accessing {{grav.user.username}}, and {{grav.user.email}}, but not {{grav.user.Level}}. I’d really like to make this work but I’ve run out of ideas. What’s the solution?

Hi, @boatful
You can access user objects only if the user is logged in. If you assigned new values or parameters to the user you must logged out/in to see the difference, and maybe clear the cache. But probably you just missed the case sensitivity. After all, the example below works as it should.

{% if grav.user.level is same as ('Visitor') %}
    {# do what you need #}
    <h1>You are a Visitor</h1>
{% endif %}

but I’d rather use user groups instead since they’re easier to manage via admin. Let’s say we create a group named “member”.

{% for group in grav.user.groups %}
    {% if group is same as ('member') %}
        {# do what you need #}
        <h1>You are a Member</h1>
    {% endif %}
{% endfor %}