Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,155 of 9,155 pages
About the help in other languages
All help pages

Role and policy operators

Showing or hiding parts of a design by role or permission: the has_role and has_policy family of operators, the fetch alternatives user/has_access_to and user/can_open, and why hiding a link is never the same as…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/role-and-policy-operators.md

On this page

Role and policy operators

This page is for designers who show something only to some users: an "Edit" link for editors, a members area link for signed-in members.

Contents

  1. The role and policy operators
  2. The fetch alternatives
  3. Node permissions
  4. Showing is not protecting
  5. Caching

The role and policy operators

Seven operators of eZTemplateRoleOperator (lib/eztemplate/classes/eztemplateroleoperator.php), described in Role and policy checks in templates:

{if $current_user|has_role( 'Editor' )} ... {/if}
{if $current_user|has_policy( 'content', 'edit' )} ... {/if}
{if $current_user|has_any_role( array( 'Editor', 'Administrator' ) )} ... {/if}

The piped value is ignored; without a user_id parameter the current user is checked.

Note

Before 6.0.15 these operators were not registered with the template engine, so a template using them got the warning "Operator 'has_role' is not registered". 6.0.15 registers all seven. On an older installation that reports the operator as unknown, use the fetch functions below, which work everywhere.

The fetch alternatives

{if fetch( 'user', 'has_access_to', hash( 'module', 'content', 'function', 'edit' ) )}
    ...
{/if}

{if fetch( 'user', 'can_open', hash( 'uri', 'setup/info' ) )}
    <a href={'setup/info'|ezurl}>...</a>
{/if}

(kernel/user/function_definition.php: has_access_to with module, function and an optional user_id; can_open with a uri.)

Node permissions

For a specific node, the node itself knows: $node.can_edit, $node.can_create, $node.can_remove, $node.can_read (Nodes, objects and attributes).

{if $node.can_edit}
    <a href={concat( 'content/edit/', $node.contentobject_id )|ezurl}>{'Edit'|i18n( 'design/mytheme' )}</a>
{/if}

Showing is not protecting

Hiding a link does not stop anyone from opening the URL. Access is enforced by roles and policies in the administration; templates only decide what to show.

Caching

Output that depends on the user's roles must be cached per role set: the view cache already varies by the user's roles; a cache-block needs $current_user.role_id_list|implode( ',' ) in its keys (Cache-block).

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x