Jump to content

Recommended Posts

Posted

I have a structure as follows

Department A
- meet 
 -- John
 -- Will

Department B
- meet
 -- Lisa
 -- Amy

I want to give Department A and B the same template with a general selector that will list only the people in its child 'meet' folder.

Normally I'd just specify a parent id but because both Departments need to list their people, I am looking to list by a path.

<?php 
$pages->find("template=a-person");
foreach($page->children(has_parent=/meet/) as $meet) {
echo "

IE

Department A will only list John and Will

Department B will only list Lisa and Amy

I'll keep hammering away at it ...

 

 

 

 

Posted

I can't use 

has_parent=id because I need my output to work for 2 different pages

Essentially I want to do this...

  • Get any child pages within a folder called "meet"

Both Department A and Department B have their own "meet" folder and must only list the contents of their own meet folder

 

Posted

DepId would be a variable of course. Listing all persons would be as easy as just "template=person"

But maybe you have a different template setup. I thought departments have template dep and meet have template persons and persons have template person.

Is it different?

Posted
Just now, bernhard said:

DepId would be a variable of course. Listing all persons would be as easy as just "template=person"

But maybe you have a different template setup. I thought departments have template dep and meet have template persons and persons have template person.

Is it different?

1

That's the correct structure.

I see what you mean about Depid being a variable. I'll try that.

 

Posted

On the department page, simply this:

// $page = department A or B
$persons = $pages->find([
  'template' => 'person',
  'has_parent' => $page,
]);

And for an overall overview:

$persons = $pages->find('template=person');

 

  • Like 2
Posted
// in your department.php template file
foreach($page->child('name=meet')->children() as $person) {
  echo "<li><a href='$person->url'>$person->title</a></li>";
}

 

  • Like 3
Posted

Thank you both. Got it working in the end with a page ID as a variable. Came back here and noticed your approaches are more efficient.

@bernhard I'm not familiar with selector properties being in square brackets. Is this called Sub-selectors: selectors within selectors on the docs page?

 

Posted
5 minutes ago, Peter Knight said:

Thank you both. Got it working in the end with a page ID as a variable. Came back here and noticed your approaches are more efficient.

@bernhard I'm not familiar with selector properties being in square brackets. Is this called Sub-selectors: selectors within selectors on the docs page?

 

No, it's selectors as associative arrays:

https://processwire.com/blog/posts/processwire-3.0.13-selector-upgrades-and-new-form-builder-version/#new-selectors-as-associative-arrays

  • 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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...