Forum
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
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:
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.
Thank you!
So when you're filtering with:
what are you trying to target there?
I'm trying to use the related data of Group, this bit really.
Now looking at it should I be using watch_group. group ?
I think you need to use
watch_group.group
, aswatch_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!
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')
wheregroup
is either the query string paramor the named segment
So you'd end up with:
or something similar.
Awesome, I'll give that a try tomorrow when I'm working and let you know.