Get page by its slug

Hi, does someone know how to get a reference to a page knowing its slug (or any other property)? I got stuck reading Laminas Navigation documentation, so any help will be appreciated!

What do you mean specifically by “get a reference”? What are you looking to do?

I’d like to get a representation object of a page using the search method. Is it possible?

You can do this with read: $api->read('sites', ['slug' => $siteSlug]);

1 Like

Thank you so much jflatnes :+1:

Of course, I didn’t read your message that carefully and gave you an example for sites, not pages. Only thing to add there is that you can have more than one thing in that array if you need it to uniquely identify the resource, so you can do ['site' => $site, 'slug' => $pageSlug].

I updated the PHP API page in the developer docs to add some more details on the common API method parameters, including this $id one.

What kind of value has the $site variable in the above code?

$site there can be the site ID ($this->currentSite()->id() if you’re in a view within a site), or it can be the site Entity object.

Great, thank you again!