Jump to content

Render Subpages Without Page-View Permission...


robobobo
 Share

Recommended Posts

Hello,

i tried to include subpages in a parent page...

The subpages should not be shown/accessible to any users especially for guests...

I built a page tree and some templates with user rights like this:

- Home

  -- Page (template -> access to all users + template-file: press-overview.php)

     --- SubPage1(template-access: no access to guest + template-file: press-article.php)

     --- SubPage2(template-access -> no access to guest + template-file: press-article.php)

     --- SubPage3(template-access -> no access to guest + template-file: press-article.php)

     --- SubPage....(template-access -> no access to guest + template-file: press-article.php)

Then I wrote something like this to include the pages in the press-overview.php:

foreach ($page->children( template=press-article') as $child) {

   $out .= $child->render(array('included'=>true)); // note: if there is no $option['included'] in the child-page then redirect...

}

... this way the content of the subpages isn't shown in the parent page for guest users ... in the frontend.

Is there a way to show pages 'included' by the 'page render function' even though the current users have no page-view-access to them"

I want to exclude these pages e.g. for sitemap.xml...

To hide the pages in the page tree is not an option!

Thanks in advance...

Robert

Link to comment
Share on other sites

I found a very simple solution!

foreach ($page->children('template=press-article, check_access=0') as $child) {

   $out .= $child->render(array('included'=>true));

}

It is quite simple: the solution is check_access=0

PW seems to have the right answer to any question!

Thanks for PW! :rolleyes:

Link to comment
Share on other sites

You don't need to remove view access at all. Just don't create a php file for the subpage template so it will not be directly viewable. So you dont need to turn access control off and can also search without adding that etc.

Link to comment
Share on other sites

Hi Soma,

thanks for your reply.

I know about the option 'template without templatefile' but in this case i can't use the render function, isn't it?

Would it be better to write my own function to render the subpages and include it, or generate the output directly on the parent page?

Please help me to find a  passable way to handle it.

Link to comment
Share on other sites

Sure, specify a template file in the render method

$out .= $child->render("yoursubtemplate.php", array('included'=>true));

Or just your template but handle the "when directly viewed" and throw a 4040

In your subpage-template

if(!count($options['pageStack'])) {
   // not rendered from other page, pageStack will be empty
   throw new Wire404Exception();
}

... render output

Or 

if(!isset($options['included'])) {
   // not rendered from other page,"included" won't exist 
   throw new Wire404Exception();
}
... render output
Link to comment
Share on other sites

Oh, thanks...

i have already done this (thats not the problem):

$out .= $child->render(array('included'=>true)); // note: if there is no $option['included'] in the child-page then redirect...

and checkt for $option['included'] in the sub-templatefile...

I think i know what you mean: the solution is not to combine the template with the templatefile and then make a reference by parameter in the render function:

$out .= $child->render("press-article.php", array('included'=>true));

My mistake is, that i associate the template with the templatefile in the PW-Backend.

Thanks for your input!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...