Peter Knight Posted October 27, 2018 Share Posted October 27, 2018 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 ... Link to comment Share on other sites More sharing options...
bernhard Posted October 27, 2018 Share Posted October 27, 2018 On mobile... Maybe I don't understand your problem. Why not just "has_parent=depId, template=person"? Link to comment Share on other sites More sharing options...
Peter Knight Posted October 27, 2018 Author Share Posted October 27, 2018 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 Link to comment Share on other sites More sharing options...
bernhard Posted October 27, 2018 Share Posted October 27, 2018 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? Link to comment Share on other sites More sharing options...
Peter Knight Posted October 27, 2018 Author Share Posted October 27, 2018 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. Link to comment Share on other sites More sharing options...
bernhard Posted October 27, 2018 Share Posted October 27, 2018 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'); 2 Link to comment Share on other sites More sharing options...
dotnetic Posted October 27, 2018 Share Posted October 27, 2018 // in your department.php template file foreach($page->child('name=meet')->children() as $person) { echo "<li><a href='$person->url'>$person->title</a></li>"; } 3 Link to comment Share on other sites More sharing options...
Peter Knight Posted October 27, 2018 Author Share Posted October 27, 2018 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? Link to comment Share on other sites More sharing options...
Zeka Posted October 27, 2018 Share Posted October 27, 2018 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 2 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