cb2004 Posted September 6, 2017 Share Posted September 6, 2017 It doesn't seem that $page->closest("template=X") is working, should it? Link to comment Share on other sites More sharing options...
cb2004 Posted September 6, 2017 Author Share Posted September 6, 2017 In fact some templates can be found, others cant, are there any stipulations? Link to comment Share on other sites More sharing options...
abdus Posted September 6, 2017 Share Posted September 6, 2017 $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 More sharing options...
cb2004 Posted September 6, 2017 Author Share Posted September 6, 2017 Ah ok, so the page I am looking for could be a child or a sibling. Interesting. Link to comment Share on other sites More sharing options...
abdus Posted September 6, 2017 Share Posted September 6, 2017 You can use a selector like this to seach among children and siblings: (use has_parent=$page to search in deeper children) $myPages = $pages->find("(parent=$page->parent, template=X), (parent=$page, template=X)"); https://processwire.com/api/selectors/#or-groups 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now