Forum

Thread tagged as: Question, Problem, Runway

Collections

Hi,

I think I'm being really thick here so any help would be great thanks.

I'm trying to get my collection of 'watches' to output to the screen, not all the details, but just a couple based on its 'group'. My Master Page currently has this:

<?php 
perch_collection('Watches',[
'template' => 'collections data/watch_group_list_item.html',
'filter' => 'group.group',
'match' => 'eq',
'value' => 'J12 Black'
]);
?>

So I'm calling my template that only displays the bit of info about the watch that I want.

Then I'm trying to filter it by the group that its part of, in this case J12 Black.

I've two questions really, 1. this doesn't return anything when I have one watch that is part of the J12 Black group. 2. I'm hardcoding J12 Black at the moment, but the page should display which ever group I'm looking at. I was thinking I could get the user to set which group at the page level or should I just the 'token' from the url ?

In fact I think it's the whole 'how do I pass values into pages' thing that I'm confused about really, how does Perch know what part of the Collection I want to look at?

Thanks, confused, Chris x

Chris Comben

Chris Comben 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the template that your collection uses?

Sure

This is watch_group_list_item.html that I'm using as this display template:

<div class="productsquare">
    <div class="details">
        <div class="title"><perch:content id="watch_model" type="text" /></div>
        <div class="cost">£<perch:content id="watch_price" type="text" /></div>
    </div>
    <img src="<perch:content id="watch_image" type="image" />" alt="<perch:content id="watch_model" type="text" /> - £<perch:content id="watch_price" type="text" />" class="product" />
    <div class="view"><a href="#" title="<perch:content id="watch_model" type="text" />"><img src="img/black/products/viewdetails.png" alt="View Details"/></a></div>
</div>

and this is the original one I've created to enter watch data, although I plan on turning it into the watch display page later on.

<perch:related id="watch_brand" collection="Brands" label="Brand" required="true">
    <p><perch:content id="brand" type="text" /></p> 
</perch:related>
<perch:related id="watch_group" collection="Group" label="Group" required="true">
    <p><perch:content id="group" type="text" /></p> 
</perch:related>
<p><perch:content id="watch_model" type="text" label="Model Name" required="true" title="true" /></p>
<p><perch:content id="watch_code" type="text" label="Suppliers Code" /></p>
<p><perch:content id="watch_price" type="text" label="Price" required="true" /></p>
<p><perch:content id="watch_image" type="image" label="Image" width="700" height="700" bucket="watches" required="true" /></p>
<p><perch:content id="watch_text" type="textarea" label="Description" count="true" /></p>
<p><perch:content id="watch_specs" type="textarea" label="Specifications" count="true" /></p>
<p><perch:content id="slug" type="slug" for="watch_brand watch_model" label="Slug" indelible="true" /></p>

Thank you!

Drew McLellan

Drew McLellan 2638 points
Perch Support

So when you're filtering with:

'filter' => 'group.group',

what are you trying to target there?

I'm trying to use the related data of Group, this bit really.

<perch:related id="watch_group" collection="Group" label="Group" required="true">
    <p><perch:content id="group" type="text" /></p> 
</perch:related>

Now looking at it should I be using watch_group. group ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you need to use watch_group.group, as watch_group is the ID of the relationship.

Oh my god that worked! It seems so simple now, thank you so much! :)

Now one small final bit please, I've hardcoded the group I'm looking up with, J12 Black, to test it. How can I get the page to know what group it should be looking up? Normally you'd have something like ?group=j12-black in the URL or similar, how does Perch do this?

Thanks again for the cracking support!

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can do that still. Or you can add a route with a named segment:

https://docs.grabaperch.com/runway/routing/named-segments/

In either case, you can read the value in using perch_get('group') where group is either the query string param

?group=whatever

or the named segment

mypage/[slug:group]

So you'd end up with:

'value' => perch_get('group'),

or something similar.

Awesome, I'll give that a try tomorrow when I'm working and let you know.