Check for permissions in Twig

By mherchel, 18 May, 2022

You can check for permissions in twig by using the snippet below.

But, how do we know what the value for the hasPermission() function should be?

The easiest way is to navigate to the admin permissions page, and inspect the checkbox for the permission you’d like to check for. Within there, you’ll see a name attribute that has the information you’re looking for.

Screenshot of markup with the permissions highlighted within the name attribute
            {% if user.hasPermission('create prospect content') %}
  <a class="button--add-team-member" href="/node/add/prospect">Add New Prospect</a>
{% endif %}