TC
Twill CMShoanghnguyen

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
PB
Patrick Boivin366d ago
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?
H
hoanghnguyen365d 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
G
geetpurwar344d ago
@hoanghnguyen Did you find any solution?