Jump to content

Output Options fieldtype


tooth-paste
 Share

Recommended Posts

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>

 

Schermafbeelding 2017-02-13 om 17.15.59.png

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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