Jump to content

Trying to find the parents


opalepatrick
 Share

Recommended Posts

Hi, 

I am trying to do this:

if ($page->parents->has("by-usage")) {

where I know the parent name exists and is called by-usage. Is this correct as I am not getting an error nor an expected result?

Thanks for the help.

Link to comment
Share on other sites

opalepatrick, 

$page->parents returns a pageArray, so you need to check for the id instead of the name.

Me thinks.

[deleted code]

Scratch that, there is some fancier stuff that goes here there than I remembered.

has() needs a page object.

$parentPage = $pages->get("/path/to/parent/");

if ($page->parents->has($parentPage)){
  • Like 1
Link to comment
Share on other sites

I don't think that works. You can use any selector though so this should work:

if ($page->parents->has("name=by-usage")) {

This is also fine:

if ($page->find("name=by-usage")->count()) {
  • Like 6
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

×
×
  • Create New...