Dan Morphis
Dan Morphis

Reputation: 1727

Allow anonymous users and authenticated users to same route

On some of my pages, I would like to show enhanced content for users that are authenticated. Is this possible? More specifically I'd like to show enhanced content to authenticated users on the "support" firewall.

I am not using the FOSUserBundle (but I could if need be). I'm using Symfony 2.7.5

firewalls:
    login:
        pattern:  ^/Login$
        security: false

    support:
        pattern:  ^/Support
        anonymous: ~

    home:
        pattern:  ^/$
        anonymous: ~

    account_create:
        pattern: ^/Account/Create$
        anonymous: ~

    secured_area:
        remember_me:
            key:      "%secret%"
            lifetime: 604800    # One week
        pattern:          ^/
        form_login:
            provider: local_auth
            check_path: login_check
            login_path: login

        logout:
            path:   logout
            target: /

Upvotes: 1

Views: 212

Answers (1)

geoB
geoB

Reputation: 4704

It is possible to do something like this in a template:

{% if is_granted('ROLE_ADMIN') %}
    {% include 'someothertemplate.html.twig' %}
{% endif %}

You have control over whatever role is assigned. Documentation available here.

Upvotes: 1

Related Questions