Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Output of $many_$many relationship in a template


Go to End


808 Views

Avatar
Turismo

Community Member, 28 Posts

26 May 2016 at 4:10am

For my CasePage.php class, I associate multiple services (ServicePage.php) via a $many_many TreeMultiselectField. On my case study pages, I've got the associated services being called in like so:

<% if $Services %>
<li>
	<% loop $Services %>
	<a href="$Link" title="$Title">$Title</a>
	<% end_loop %>
</li>

However, I now want to call a featured case study (CasePage) onto my Service pages (ServicePage) based on this relationship i.e. only a case study which has this service page associated with it (and ideally the most recently added case study).

Can someone please advise how I output this in my CasePage.ss template? Do I need a controller function in place first?