Forum

Thread tagged as: Question, Runway

How to generate a list of related items from Collections

Building our first site in Runway... and using Collections for content types - Products, Producers and Regions.

We are using one list/detail Product page and perch:related inside the detail content template to load a template of Producers, so it displays in the detail view of Product. That is all good. But we want to generate a list of other items related to the Producer in this template.

Is there an ideal way to do this??

Stuart Farrell

Stuart Farrell 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd list your Producers collection, using a template with the required perch:related tags to display the related content.

Yeah so, in our detail template we have:

<perch:related id="producerDetails" collection="Producer" label="Producer" divider-before="ABOUT THE PRODUCER" >
   <perch:template path="content/producer.html" />
</perch:related>

But inside this "producer" template, how can we list other items by this same producer?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to pull that data from the Items collection.

OK, we added some system variables...

foreach($producersCoffeeList as $producerCoffeeList) {
$arrayProducer[] = $producerCoffeeList['coffeeTitle'];
$arrayProducerLink[] = $producerCoffeeList['slug'];
}

PerchSystem::set_var('arrayProducer',$arrayProducer);
PerchSystem::set_var('arrayProducerLink',$arrayProducerLink);

(Producer template)

<perch:content id="arrayProducer" collection="Coffee">
<li>
   <a href="coffee.php?item=<perch:content id="arrayProducerLink" />&producer=<perch:content id="producerName" />&origin=<perch:content id="???" />">
   <perch:content id="arrayProducer" />
   </a>
</li>
</perch:content>

Gotta work out Origin yet, but is this the best way to go about this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's origin? I'm completely lost!

Sorry - Region, just one of the collections.

We will add another array for that.... but is this method the best approach for Runway and Collections?