Checking if a user can view a child page
Permalink
Hi,
I have the following code
I am trying to programatically create a list of available pages to the user with a link attached to the page.
How do I check whether the current user has access to view the current child page that is in the loop, and how would I attach a link to that child page to direct them to the page?
I have tried but it did not seem to do anything but cause an error.
I have the following code
<?php $page = \Page::getCurrentPage(); $children = $page->getCollectionChildren(); $counter = 1; foreach($children as $child){ if($counter == 4){ echo "<div class='row'>"; } if($counter == 8){ echo "<div class='row'>"; } $childName = $child->getCollectionName(); echo "<div class='col-md-3'><div class='well'>"; echo $childName; echo "</div></div>";
Viewing 15 lines of 24 lines. View entire code block.
I am trying to programatically create a list of available pages to the user with a link attached to the page.
How do I check whether the current user has access to view the current child page that is in the loop, and how would I attach a link to that child page to direct them to the page?
I have tried
$child->canViewPage();
You can try this. I wrapped the changes in "CHANGES" and "END CHANGES".
Each child is a Page object that you can check the permissions of.