However, @bvdputte is right. It might actually make much more sense to store the collection page in a cookie or pass it on as a URL parameter and link to the real URL of each module instead.
The toolkit has the $cookie::set()
and $cookie::get()
methods you need for that.
Ok, let’s try that cookie. so I have a collection
page with a list of items
.
In the collection
template:
<? $collection = $page->title()->html(); ?>
<? // cookie::set('collection', $collection); ?>
<? $items = $page->items()->toStructure(); ?>
<? foreach($items as $item_id) { ?>
<? $item = page('items')->find($item_id) ?>
<li><a href="<?= $item->url() . '/collection:' . $collection ?>"><?= $item->title()->html() ?></a></li>
<? } ?>
Same thing in the item
template:
<? // $collection = cookie::get('collection'); ?>
<? $collection = urldecode(param('collection')) ?>
<? $items = page('collections')->children()->find($collection)->items()->toStructure(); ?>
<? foreach($items as $item_id) { ?>
<? $item = page('items')->find($item_id) ?>
<li><a href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<? } ?>
A few more questions:
- do I need the cookie AND the url param when I could just use the url param?
- Does it solve the SEO problem at the same time, or do I still have to consider the
link
to a default version?
Thank you very much for your help.
No.
Yes, if the collection is basically a list of links, we don’t have any duplicate content anymore. All collections point to the same page, so there is no “default” version to link to, anyway.
Apart from that, I don’t understand the item
template. Where does the library param come from? Shouldn’t that be collection
and the variable $collection
?
Oups… Yes it should be named collection
and I edited the post. Thank you very much for your help. You and Kirby rock!