Implemented Method to check permissions in a template

xf_phantom

Well-known member
Since we don't "need" to use template hooks anymore, it would be really cool if we could check the $visitor permissions in the template too.

Because of the missing template hook code, i would need to use the proxy class system to extend the controller to attach only
PHP:
$parentReturn->params['canViewFoo'] = XenForo_Visitor::getInstance()->hasPermission('my_addon','view');

Would be nice to avoid the overhead and be able to check the permission direct in the template
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
You can already do this. The visitor object contains all of the unserialized permissions:

Code:
<xen:if is="{$visitor.permissions.group.permission}">

Where group is the permissions group, eg forum and permission is the actual permission eg view.
 
@Chris D any tips on how to do this for Xenforo 2? I've got the add-on I'm about to release checking permissions via a php file and I want to add a phrase for part of it which leaves me not able to because if I add a phrase in a string it doesn't work. If I could check the permissions in part of the template that would really help. Thanks if you have any idea.

- Brad
 
@Chris D I tried this but it doesn't work. It works for me in the php file but not the template:

HTML:
<xen:if is="$xf.visitor.hasPermission('permissionGroup', 'permission')">{{ phrase('myPhrase') }}</xen:if>
 
@Chris D I tried this but it doesn't work. It works for me in the php file but not the template:

HTML:
<xen:if is="$xf.visitor.hasPermission('permissionGroup', 'permission')">{{ phrase('myPhrase') }}</xen:if>
You are using a combo of XF1 and XF2 syntax. Try this...
HTML:
<xf:if is="{{ $xf.visitor.hasPermission('permissionGroup', 'permission') }}">{{ phrase('myPhrase') }}</xf:if>
 
Back
Top Bottom