Forum
Detail one Collection item but list other collection items on same page
Hello, all! I've got a Perch Runway Collection called "Properties" and am displaying a detail view of same on a properties.php page like so:
<?php
$properties = perch_collection('Properties', [
'template' => 'properties.html',
'filter' => 'property_slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
'skip-template' => true,
'return-html' => true,
]);
?>
<?php echo $properties['html']; ?>
This works well, but at the bottom of the page I want to display links to other items in the collection; the ones that do not match on the property_slug
.
I tried this:
<?php
$properties = perch_collection('Properties', [
'template' => 'properties.html',
'filter' => 'property_slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
'skip-template' => true,
'return-html' => true,
]);
$properties_grid = perch_collection('Properties', [
'template' => 'properties-grid.html',
'filter' => 'property_slug',
'match' => 'neq',
'value' => perch_get('s'),
'skip-template' => true,
'return-html' => true,
]);
?>
<?php echo $properties['html']; ?>
<?php echo $properties_grid['html']; ?>
...but where $properties_grid
should echo, there's nothing, and there's no obvious error in the debugger.
You don't need
skip-template
orreturn-html
, or to assign the function calls to variables. Just callperch_collection
and pass in the parametersI think that was one of the first things I tried:
The
properties.html
echos, but theproperties-grid.html
does not. I get nothing between "Argle" and "Bargle".What does debug tell you?
I'm not seeing any missing files or variables in Debug, but I'm not particularly adept yet at reading it yet:
It looks like 3 items are being templated with
properties-grid.html
. Does that sound about right?Actually, the main template for properties is
properties.html
. It's both the template for Perch Admin input and the main output template forproperties.php
.I wrote
properties-grid.html
just to handle layout of a "Other Regional Properties" section at the bottom of the properties.php page. It should display all the other Properties except the one that is being detailed.You've got the whole thing wrapped in a
perch:related
tag - what's the purpose of that?That code block, in the page, without
<perch:related>
does produce something, but only shows the item featured on the page already.I want to display the other items in the collection, or at least links to them.
I guess what I am trying to stumble toward could be called a "self-join" but I don't know how to achieve that in Runway.
Have you moved on from the original question? I thought you wanted to display the matching property, and then after that other properties from the same collection. None of that requires a relationship or a self-join.
Yes, my goal is to simply to display other properties from the collection on the same page as detail from one item in that same collection.
The fact that I don't seem to be able to get it to work made me wonder if conceptually what I was trying to do was a self-join, which perhaps is not doable in Runway? I'm not a db expert but I know from working in FileMaker you often have to have intermediate tables to get self-joins to work.
I'm happy to not mess with self-joins if I don't have to!
Just sticking to the default template for illustrative purposes, does this do what you want?
Thanks, Drew, that was a helpful suggestion to debug this.
I modified my default template to add the two perch_collection blocks as you suggested. That successfully pulled all the Properties to the page, with the target property at the top. By modifying it further:
...I got what I need, which is the detail layout, then the
properties-grid
below.The file
properties-grid-xrelated.html
is the same version of my previous file, with the<perch:related>
tag removed as you suggested above. Oddly, yesterday when I simply removed<perch:related>
from the previous file and refreshed, that didn't work. Saving a new file with a new name seemed to do the trick. Are the templates cached?Anyway, I next copied the same perch_collection call in my property.php file and that also worked (mostly).
Now I have a niggling issue relating to a Collection item ("States") inside my Collection items ("Properties") returning an array number instead of a value in the above properties-grid. I think perhaps I will mark this topic as solved and start a new one.
PHP caches all files to some extent. If you're in development mode we attempt to override that.
Documentation of
PERCH_PRODUCTION_MODE
is a bit sparse. On the Troubleshooting Tips page I read:Shouldn't it be
PERCH_DEVELOPMENT
mode in which caching is overridden? I would thinkPERCH_PRODUCTION
would be the default live mode in which caching is fully leveraged.Also, how do you set that? I presume in /config/config.php like this...
Or should it be...
No, it should be the constant: