We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Runway

Perch Runway Headless Related

Hi,

Using Runway, I'm trying to get items in a collection, and it returns the items beautifully. I've got a perch:related section in Perch, but at the moment the JSON returns the ID of the related item, rather than the content of the related item.

How can I return the related items details?

Cheers.

Ryan Gittings

Ryan Gittings 1 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd query the related collection using the IDs that you now have.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Could they be returned as part of the same "set", in the same location within the item?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure I understand the question.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

So, can the related items data, be included within the same area as the related collection currently is (currently appearing as an ID), or would it need to be returned as part of a new set?

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

My current code:

<?php
    $Headless   = $API->get('HeadlessAPI');
    $Response   = $Headless->new_response();

    $Collections = $API->get('ContentCollections');
    $Collection  = $Collections->find('Videos');

    $Set = $Headless->new_set('video');

    $Set->add_items($Collection->query([
      'count' => 1,
      'filter' => 'featured',
      'match' => 'eq',
      'value' => 'true'
    ]));

    $Response->add_set($Set);

    $Response->respond();
Drew McLellan

Drew McLellan 2638 points
Perch Support

The most efficient way would be to fetch your content and the related items and join them back together at the front end. That'll save you retrieving each related item each time it's used. You'll just get it back once.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Ah, so you're saying to use separate API calls?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, I'd add them to the same response as a new set.

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

Gotcha.

Yeah that makes sense, thanks Drew.