Thread tagged as: Question, Discussion, Runway

Output from multiple collections using different templates


Following on from my previous thread:

I have ran into a little roadblock that I can't seem to figure out.

I have two collections setup, one named articles and one named testimonials. The articles collection uses an article based template with the standard fields you would expect, title, image, body, summary, date. The testimonials collection uses a template with fields including testimonial and name.

I can't seem to figure out how to output the items in date order using the two different templates.

Using the following function, I did manage to output both collections when they both used the same template.

perch_collection(['Articles','Stories'], [
'template' => 'list.html',
'sort' => 'date',
'sort-order' => 'DESC'
Marc Sanders

Marc Sanders 0 points

  • 3 years ago

For reference, this is what I am trying to create:

I'm not sure if it would be easier using the blog app and two different post types?

Duncan Revell

Duncan Revell 78 points
Registered Developer

Both collections need to have a date field with the same name (I guess date - so you can sort by this field).

Then create a template that includes the fields you want to see from both collections. This template might need a fair few if exists tags to keep things tidy, but it should work.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If not, you can use _date.

I will looking at putting the template and solution together a little later. Will feedback once complete.

Thanks for the suggestions so far both.

Got it all working, thank you both for your help. I will post a link to the site once complete.

Just out of interest Drew, what is the _date field. How is it populated, is it updated each time the region is edited or populated with the date the region was created?

Drew McLellan

Drew McLellan 2638 points
Perch Support

_date is the collection item's creation date.