Forum
Trouble selecting a single entry with perch_content_custom
Hi!
I'm trying to do something really simple and have gotten stuck. I basically just need to select a single entry based on it's slug, and have that display in a page. Derpy simple.
I've got this:
<?php include('perch/runtime.php'); ?>
<?php $Q = perch_get('s');
$p = perch_content_custom("Shows", array(
"template" => "single-show.html",
"skip-template" => true,
"filter" => "show-slug",
"match" => "eq",
"value" => $Q
));
echo perch_get('s');
var_dump($p);
?>
in a page called show.php
sitting in the root folder. I've got skip_template
in there for now for debugging.
If I remove all teh filtering I get all my records, so I know it works, and is selecting the right collection and all that. I can also see that all shows have a show-slug
field.
When I add back the filtering it returns an empty array.
The collection(region?) has got "share across pages" switched on.
Any ideas? Thanks!
Have you echoed the value of $Q to check it is the slug?
If you enable debug on that page what do you get?
Why do you have share across all pages? I'm not sure why that is relevant.
Hi Rachel! I actually started using Perch after hearing you on Jen's show :) Cool to see you in the forum!
Ya I've echoed it out and see that it's getting populated correctly.
I just switched on debugging, and here's what I get:
Thanks for the help!!
I mention it being shared across pages, since when I go to the "pages" part in the admin panel, it says "Shared", and "home".
Basically what I'm trying to do is build a single page site with a modal that can be invoked to show a single item's details. So all the main info lives on this home page, but at the same time I want to be able to show a single record from that big list in more detail in a modal.
This page I'm trying to put together will be called by jquery and injected into a modal container. Maybe there's a better way to do this. :)
I think this is maybe all caused by me not really getting the difference between "allow multiple items" and the normal "single item" option.
Right now I have one "item" (a show) which contains many different shows. Is that the wrong way to go about this? I'm a bit confused as to the difference there. :/
How is your template structured?
Hi Drew,
So I have a page
show.php
with this:and then my template,
_single-show.html
has this:The perch content tags at the top are me flailing about trying to figure out what's happening. :p
Basically now, when I remove the filter, I get all my shows, but with the filter on it returns nothing, and doesn't even inject the template.
The "Show" region is created on index.php, and looks like this:
and that is using this template:
Thanks for any help you can offer!!
If you add
<perch:showall />
to your template, can you see theshow-slug
properly populated?How much content do you currently have? I ask because all your IDs are invalid and I'm wondering how much work it would be to correct them.
ha! I figured it was something fundamental like that. :p What constitutes a valid field ID? I assume it's the
-
that wrecks it?I have literally about 4 records so that's not an issue at all. I'll try the
showall
thing and report back.ya weirdly enough it looks like it's populated. :/
I've now removed all the dashes from the field IDs and still no jazz. :(
AHH ok so I restructured this a bit and I think it comes down to having a
<perch:repeater>
in the template that I used to define the regions' fields.I had it like this originally because of how things are to be displayed on the site.
So now the template linked with the region that defines the "model" for the region is almost only perch field tags. Then I'm using Content Custom to actually show the content on the page.
Ok - so is it working?
ya it is now. I ended up dumping the whole DB a few times before getting it right.
I had not really understood that the repeater was for repeating something inside of a single entry record. I had been making my entire list of shows inside of one record w/ a repeater. :O
I'll just RTFM a little better next time. Loving Perch though!