I have written a custom block to allow users to select an item from a collection. This works perfectly but it stores the content of the linked item in the block.
Is there a way to create a link (as in a relationship like an id
) to a collection item so that if the collection item’s content is updated, the content of the block will also update?
Collection
return function($site) {
return $site->find('testimonials');
};
Block blueprint
name: Testimonial
icon: bolt
fields:
testimonial:
label: Testimonial
type: select
options: query
query:
fetch: kirby.collection("testimonials").testimonials.toStructure
text: "{{ structureItem.author }}"
value: "{{ structureItem.text }}::{{ structureItem.author }}"
Block snippet
<?php
$testimonial = $block->testimonial();
$split = explode('::', $testimonial);
$text = $split[0];
$author = $split[1];
?><blockquote>
<p><?= $text ?></p>
<cite class="font-black uppercase text-sm"><?= $author ?></cite>
</blockquote>
I hope this makes sense.
Thanks