Using a block to relate a collection item

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?


return function($site) {
    return $site->find('testimonials');

Block blueprint

name: Testimonial
icon: bolt
        label: Testimonial
        type: select
        options: query
            fetch: kirby.collection("testimonials").testimonials.toStructure
            text: "{{ }}"
            value: "{{ structureItem.text }}::{{ }}"

Block snippet

$testimonial =  $block->testimonial();
$split = explode('::', $testimonial);
$text = $split[0];
$author = $split[1];

    <p><?= $text ?></p>
    <cite class="font-black uppercase text-sm"><?= $author ?></cite>

I hope this makes sense.


The value here defines what you actually store about your item in the field. It would make more sense to store an ID, e.g. one added automatically using the AutoID plugin.

1 Like

Yes, exactly… That looks like the sort of thing I need. I’ll try it out.

Thank you

Using AutoID worked perfectly. Thank you.