Jump to content

$page->closest("template=X") not working


cb2004
 Share

Recommended Posts

$page->closest() method works only on parents (including $page). If $page doesn't have a parent with template X, youll get a NullPage. 

From the docs:

 
/**
 * Find the closest parent page matching your selector
 * 
 * This is like `$page->parent()` but includes the current Page in the possible pages that can be matched,
 * and the $selector argument is required. 
 * 
 * #pw-group-traversal
 * 
 * @param string|array $selector Selector string to match. 
 * @return Page|NullPage $selector Returns the current Page or closest parent matching the selector. Returns NullPage when no match.
 *
 */
public function closest($selector) {
    if(empty($selector) || $this->matches($selector)) return $this; 
    return $this->parent($selector); 
}

 

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