Log in |
Detecting User Roles in DTMLYou may want to customize the look and feel of a page based on the roles of the user viewing it. How can this be done in DTML? You can find out if a user has a role with a <!--#if "AUTHENTICATED_USER.has_role('somerole')"--> ... <!--#/if--> Note: Note: You may also pass a list of roles to Zope 2 introduced the notion of local roles which
complicates things a little. It is possible to have
different roles for different objects. So if I am a
To get the real roles that the user has in the context of a given object (which takes into account local roles given in that object and in other object higher up in the hierarchy), you need to also pass in an object for context. For example: <!--#if "AUTHENTICATED_USER.has_role('Owner',this())"--> You own this Folder. <!--#/if--> Note: You can also test for permissions on objects like so: <!--#if "AUTTHENTICATED_USER.has_permission('View',someObject)"--> ... <!--#/if--> Using permissions rather than role will tell you if a user is authorized to perform a give action on a given object. |