H.W. H.W. - 2 years ago 148
PHP Question

Symfony2 check if user has access to url inside Twig

Is there a way in Symfony2 to check if user has access to specified url inside Twig template?

Something like this:

{% if user_has_access( '/some/url/to/access' ) %}
<a href="{{ path( '/some/url/to/access' ) }}">You can come here</a>
{% endif %}

Answer Source

Like PaweĊ‚ Brzoski explained, it's possible to create a custom twig function.

But in Symfony, the correct way is to use is_granted('ROLE_...')

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download