view raw
H.W. H.W. - 11 months ago 74
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 %}


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_...')