Jump to content

Get all roles of a template


suntrop
 Share

Recommended Posts

Hi all.

I have pages (templates) that are only accessible to certain users. Now I need to get all users that have view access to specific pages (they will get email when page updates).

I thought of something like this:

$template = wire('templates')->get($p->template);
$roles = $template->getRoles();
$users = wire('pages')->find('template=user, roles=' . $roles);

But it looks like getRoles() doesn't returns the roles for that template. Roles is an empty PageArray. What is wrong or is there another way to get those users?

Link to comment
Share on other sites

The following works for me. You first have to enable 'Do you want to manage view and edit access.....' in the Access tab when editing that template.

//$t = $page->template;//if on this page
$t = $templates->get("skyscraper");
//echo $t->name . '<br>';//confirm we are looking at the right template

$tRoles = $t->getRoles();

foreach ($tRoles as $r) {
echo $r->name . '<br>';
}

getRoles() seem only to work if 'view pages' permission is enabled on that template for a role.

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...