Jump to content

Using $page->render() on unpublished pages return 500 Error


Lars282
 Share

Recommended Posts

Hi,

I am trying to give my editors the option to share unpublished pages with externals for review, without moving or copying the actual page in the admin.

I have now created a draft template, that has one field (a page). Whenever the draft template is accessed, it should render the page selected in that field. This works fine as long as I am logged in. When I am not logged in, the $page->render() on the unpublished pages leads to 500 internal server error.

Any idea why? Below the code I am using. Can I use $page->render() on unpublished pages?

Thanks!

Lars

<?php
	if($page->draft_article) { //draft_article is the field where I select the article to be shown
		$out = $page->draft_article->render(); //when the page selected in draft_article is unpublished, guests get a 500 error with this line
		echo $out;
	} else {
		echo 'No article selected.';
	}
?>
Link to comment
Share on other sites

if ($page->draft_article) will always return true, no matter if it is published or not.

Remember that $page->draft_article is an object, so you're asking if (object)

Probably you're better of with: $page->draft_article->viewable() or $page->draft_article->editable() or something.

if ($page->draft_article->id && $page->draft_article->viewable()) {

}
I'm nor saying this is a solution, but it it can get you started.
Link to comment
Share on other sites

Thanks! Seems to be the issue that render check if the page is viewable, as when the page is in any other status, the code works fine. Still surprised that this returns a 500 internal server error.

If $page->render checks if the page is viewable, is there any other way to display an unpublished page? Publishing and keeping the page hidden might work, but will involve additional steps of hiding / unhiding the page ...

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...