Jump to content

Recommended Posts

Posted

why does an if statement like this not work as expected...

if($input->urlSegment2 OR !isset($page))

... i try to execute different php-code in my head.inc for direct page calls (if this ist the right term, www.domain.tld/entry/page-name/ where template "entry" uses the $page array) and such that make use of urlSegments with infos for $pages->find in a different template. What i`m doing wrong?

Posted

This won't work because the $page variable will always be set. If you want to test for the existence of segments, this will be enough if($input->urlSegment1)

Posted

hm, but how can I make a distinction like this?

if(isset($page)) {
$parent_page = $page->parent;
}else{
$parent_page = $input->urlSegment2;
}
Posted

I think you can check against $page->id instead of $page.

mhm, no, works only for a if true condition. but

if(!$page instanceof NullPage)

did it.

Posted

That should work. To minimize the code you can also try to turnaround the statement using an ifnot (!).

if (!$page->id) {
  // do stuff
}

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
  • Recently Browsing   0 members

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