I’m trying out the new Kirby editor plugin and I’m struggling to get a file object of a block collection, in order to resize the stored images of each block and use them as a thumbnail.
Any advice?
<?php foreach($page->aside()->blocks()->filterBy('type', 'image') as $thumb): # List project-links ?>
<?= $thumb->content()->toFile()->url() ?>
<?php endforeach ?>
texnixe
October 2, 2019, 10:29am
#2
What does $thumb
return if you do a dump($thumb)
?
m-artin
October 2, 2019, 10:56am
#3
Looks like it returns an ImageBlock object:
Kirby\Editor\ImageBlock Object
(
[attrs:protected] => Kirby\Cms\Content Object
(
[guid] => /pages/films/film-project/xyz.jpg
[src] => http://localhost:8888/media/pages/films/film-project/xyz.jpg
[id] => films/film-project/xyz.jpg
[ratio] => 1.3461538461538
[caption] =>
) …
[files] => Kirby\Cms\Files Object
(
[0] => films/film-project/xyz-a.jpg
[1] => films/film-project/xyz-b.jpg
[2] => films/film-project/xyz-c.jpg
[3] => films/film-project/xyz-d.jpg
) …
I have shortened the output and can also send you a message with the complete dump if you want.
texnixe
October 2, 2019, 11:33am
#4
Here we have a file Id we could use. The question is where the files
array comes from.
m-artin
October 2, 2019, 12:06pm
#5
Thanks @texnixe , I will take a different approach then and will create an additional image field in the blueprint to select a poster image.
texnixe
October 2, 2019, 12:13pm
#6
<?php foreach($page->text()->blocks()->filterBy('type', 'image') as $block): # List project-links ?>
<?php dump($block->attrs()->id()->toFile()) ?>
<?php endforeach ?>
This gives you the file object
1 Like