tooth-paste Posted February 13, 2017 Posted February 13, 2017 How can I output 'Coaches' who are working in multiple provinces? I'am using the 'Options' Fieldtype. In the back-end it is possible to select multiple provinces on every single coach. How can I output 'Friesland' for instance? So every coach who selected 'Friesland'? <ul> <?php $coaches = $pages->find("template=coach, sort=coach_locatie"); foreach ($coaches as $coach) { echo '<li><a href="">'. $coach->title .'</a>'. $coach->coach_locatie .'</li>'; } ?> </ul>
Robin S Posted February 14, 2017 Posted February 14, 2017 You could do this: foreach($coaches as $coach) { $provinces = $coach->coach_locatie->implode(', ', 'title'); echo '<li><a href="">'. $coach->title .'</a>'. $provinces .'</li>'; } Not sure why you are placing your coach pages as children of a province when you are also selecting multiple provinces in your options field - normally you would use a Page Reference or Options field to show the province relation, or use a parent/child structure to show the relation, but not both.
tooth-paste Posted February 14, 2017 Author Posted February 14, 2017 Quote You could do this: This script does work! It is outputting all provinces. It is a bit the other way around. Quote Not sure why you are placing your coach pages as children of a province What would you suggest? In alphabetic order? Can I still output different provinces on a single coach when structure is alphabetic?
Robin S Posted February 14, 2017 Posted February 14, 2017 I can't tell from your first post what you're trying to do. $coaches = $pages->find("template=coach, sort=coach_locatie"); This gets all coach pages, regardless of province. If you want the coaches for a single province you include that province in your selector: $friesland_coaches = $pages->find("template=coach, coach_locatie=Friesland"); 40 minutes ago, tooth-paste said: What would you suggest? In alphabetic order? Can I still output different provinces on a single coach when structure is alphabetic? You can put the coach pages in any order that suits you - the point is that you don't want to make coach pages children of province pages if a coach may belong to more than one province. Otherwise you get into a situation where you need duplicate copies of coach pages under more than one parent. You can just put all your coaches under a parent called "coaches" and then set any attributes for them such as province using a Page Reference or Options field (a Page Reference usually works out being more flexible in the future). If there is going to be a front-end page "Friesland" that lists all coaches for Friesland then a Page Reference field is definitely preferable to an Options field. 1
tooth-paste Posted February 14, 2017 Author Posted February 14, 2017 Ok, thanks! I will change the structure as you suggest. I have still a question. In your comment you talk about 'Page Reference' do sort out the different provinces. What do you mean with 'Pag Reference'? I don't understand. Is it the Fieldtype 'Page'?
kongondo Posted February 14, 2017 Posted February 14, 2017 9 minutes ago, tooth-paste said: What do you mean with 'Pag Reference'? I don't understand. Is it the Fieldtype 'Page'? Yes...it is. 1
tooth-paste Posted February 14, 2017 Author Posted February 14, 2017 THX will check the possibilities!
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