Using Permissions in Templates

Checking permissions in templates is an important aspect of implementing a permissions system. For example, if a user is not allowed to create a page, then there's no point in showing them a Create Page button.


Alternatively, you could show them the button then if they click on it give them a message as to why they can't use it. Even in this example you would likely need to check the permissions in the template so you know to display the alternative message.

To check permissions in templates, use the is_allowed modifier on the name of the permission. This modifier allows you to check a single permission at a time, and returns either true or false.


If you need more complex permissions checks, it is recommended you process these in your controller script rather than in the template.

Example 7.5. Checking a Permission From Within a Template

{if 'some:permission'|is_allowed}
    <input type="submit" value="Create Something" />
    <input type="submit" value="Create Something" disabled="disabled" />