Forum

Thread tagged as: Runway

Targeting a "parent" Collection from inside a "child" Collection.

Hello, folks! If you are treating a Runway Collection as a "child" of another Collection, how do you target the "parent" Collection inside "child" Collections output?

I've got a site with this structure:

Home
  > Locality A
        >> Property 1
        >> Property 2
  > Locality B
        >> Property 3
        >> Property 4

Both Localities and Properties are Collections. Both have their own Master page and their own page in Perch Admin.

In Perch Admin, I've given my Localities page a URL Pattern of [slug:s].

I've given my Properties page a URL Pattern of [slug]/[slug:s].

So, on Properties pages, I'm trying to build a navigational element to other siblings.

Here is my PHP for pulling the siblings Properties into the properties.php page:

<?php
  perch_collection('Properties', [
    'template'  => 'properties-grid.html',
    'filter'    => 'property_slug',
    'match'     => 'neq',
    'value'     => perch_get('s'),
  ]);
?>

And here is the properties-grid.html layout template I am trying to populate:

<a href="/<perch:content id="locality_slug" type="slug" />/<perch:content id="property_slug" type="slug" />/">
  <div class="properties-grid-wrapper">
    <img src="<perch:content id="property_thumbnail" type="image" />" alt="<perch:content id="property_name" />">
  </div>
  <h2><perch:content id="property_name" /></h2>
</a>

The above does display the sibling Properties, but I can't figure out how to inject that locality_slug value in the href, since it is not part of the Properties collection.

Your assistance is appreciated!

Joel Davies

Joel Davies 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you name it in the route:

[slug:locality]/[slug:s]

you should then have it available as url_locality in your template.

Thanks, Drew! Per your suggestion, I changed the route on my Properties page to [slug:locality]/[slug:s]. Then in my template HTML file I put:

<a href="<perch:content id="url_locality" type="slug" />/<perch:content id="property_slug" type="slug" />/">
<-- Other stuff -->
</a>

But that gave me links that the browser resolved like this:

https://localhost/gotham/gotham-square/gotham/gotham-park-place/

Gotham is the Parent Locality, Gotham Square is the Child page and Gotham Park Place is the sibling page I'm trying to link to. Not good!

Took me a while to figure out what I had done wrong -- I forgot to start my href with a root-relative "/"!

<a href="/<perch:content id="url_locality" type="slug" />/<perch:content id="property_slug" type="slug" />/">

That did the trick, giving me https://localhost/gotham/gotham-park-place/ for a sibling link.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so that's not a problem is it?

No, your suggestion works. I was just documenting a small mistake I initially made implementing it for the benefit of others who might have the same issue.