Forum
Filter by category question
Hi
I'm using this to filter a perch_collection
perch_collection('Films',[
'template' => 'list.html',
// Hardcode category path - how do I make this dynamic?
'category' => 'film/buy/dvd/limited-edition/',
]);
The category
value is fixed, at this point the template is filtering the collection
by this path
film/buy/dvd/limited-edition/
How do I make anything after the set
name dynamic?
I'm using routes:
film/[slug:buy]/[slug:format]/[slug:edition]
film/[slug:buy]/[slug:format]
film/[slug:buy]
film
Update
Adding this works
perch_collection('Films',[
'template' => 'list.html',
// Dynamic path
'category' => 'film/'.perch_get('buy').'/'.perch_get('format').'/'.perch_get('edition'),
]);
Hello Stephen,
If you are on
/film/buy
, you'd have 2 trailing slashes'category' => 'film/buy//
which I don't think works for filtering.Try using something more robust. Perhaps something like this:
Hi Hussein,
Thanks for taking a look at this. I'm not seeing the problem with 2 trailing slashes.
It's working at the moment using the example I posted, however I do like the use of
$catPath
variable. Feels cleaner :)