Jump to content

Recommended Posts

Posted

Hi, was just wondering what the best way to access a page field in a selector would be?

Is ID the only way? So:

$geo_students = $pages->find('template=student, subject=1102, sort=title');

Or would there be another way?

Thanks.

Posted (edited)
$biology = $pages->get("/subjects/biology/");

$biology_students = $pages->find("template=student, subject=$biology, sort=title");

It does pretty much the same as your code, but in a more readable way. Also works with multiple pages like this:

$subjects = $pages->find("template=subject, some_selector=value");

$students = $pages->find("template=student, subject=$subjects, sort=title");
Edited by apeisa
removed the unnecessary $this from code examples.
  • Like 1
Posted

Thanks Apeisa, helpful as always!

What's the purpose of $this?

for use in modules: ( after sertain dependencies are loaded )

$this->pages->get('/url/')

works everywhere: (maybee some overhead)

wire('pages')->get('/url/')

works within templates:

$pages->get();

Posted

You should also be able to do this:

$biology_students = $pages->find("template=student, subject=/subjects/biology/, sort=title");
  • Like 2

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
×
×
  • Create New...