Forum
Retrieving single item URL when displaying content from multiple collections
I'm mixing together items from multiple collections like this:
perch_collection(['Ring & Pinion','Bearing Kit', 'Installation Kit', 'Portal Wheel End'],[
'sort'=>'title',
'sort-order' => 'ASC',
]);
This uses the default template from the first collection 'Ring & Pinion', which is mostly okay because the IDs for the default templates from all 4 regions mostly match. However, I need to link to each item and that's where things get tricky. In the region templates, the links for each item are created like this:
<a href="/products/ring-and-pinion/<perch:content id="slug" type="slug" for="title" />">
<a href="/products/bearing-kit/<perch:content id="slug" type="slug" for="title" />">
<a href="/products/installation-kit/<perch:content id="slug" type="slug" for="title" />">
<a href="/products/portal-wheel-end/<perch:content id="slug" type="slug" for="title" />">
Using the perch_collection([])
above, this means all of the regions output the /products/ring-and-pinion URL instead of their respective URLs.
What are my options? Is it possible to utilize the 'URL for single items' set in the collection options somehow? Or, is it possible to use 'each' => function($item) { },
with perch_collection
to somehow determine which region each item is being pulled from?
If anyone has run into this problem before, I would really appreciate some advice! I've searched all over the docs/forum to no avail. Thanks!
What information have you got to enable you to detect where it's come from?
That's the thing...there's really no distinguishing content other than the collection title. Would it be possible to save some kind of defining content within each collection item without causing extra work for the editor? Like save some hidden field directly in the collection template?
Yes, that could work.
How? I tried <perch:content type="hidden" id="category_slug" default="ring-and-pinion" /> but that doesn't save. Is there something else like that I can use?
I think you'd need to set the
value
.<perch:content type="hidden" id="category_slug" value="ring-and-pinion" />
doesn't save either and doesn't show up in<perch:showall />
. How do I set the value of a hidden field in a template?For now, I've solved this with
and in /perch/addons/plugins/ui/_config.inc
It would be really great to be able to access the collection item's 'URL for single items' from within the template using a special ID. Please add as a feature request.