Render repeater in block blade file

I have made a block named "gallery" with a repeater containing medias named "gallery-item", please help me to display the images in the blade file of the block. (I tried with regular block with {{ $block->image(...) }} but don't know how to do with blocks with repeaters). I tried this example but it doesn't work: https://twillcms.com/docs/block-editor/creating-a-block-editor.html#content-rendering-helpers Thank you very much.
Twill
3 Replies
Patrick Boivin
Hi @hoanghnguyen, I haven't used this in a while but if I remember correctly, repeaters inside of blocks are saved as child blocks. You should be able to do something like this :
$image = $model->blocks->first()->children->first()->image('role');
$image = $model->blocks->first()->children->first()->image('role');
Not sure about the new blade helpers... Does this: $repeaterItem->renderData->block->image(...) not work for you?
hoanghnguyen
hoanghnguyenOP2y ago
Thank you very much @pboivin, I modified my code based on your answer and this works for me: @foreach($block->children as $repeaterItem) <img src="{{ $repeaterItem->image('gallery-item') }}" alt="" /> @endforeach -------- This doesn't work for me in my case... or maybe because I don't know how to define $repeater... @foreach ($repeater('gallery-item') as $repeaterItem) <li> <img src="{{ $repeaterItem->renderData->block->image('slider', 'desktop', ['h' => 850]) }}" alt=""> {{ $repeaterItem->renderData->block->input('title') }} </li> @endforeach
geetpurwar
geetpurwar2y ago
@hoanghnguyen Did you find any solution?
Want results from more Discord servers?
Add your server