How to display image from InlineRepeater
I want to dispaly the image from InlineRepeater.
Please help me how to do it.
33 Replies
Hi, @ifox , Please look at this.
I want to display this image in blade. How to do this?
<img src="{{ $feature['medias']['image'][0]['original'] }}" />
I can display using this but is there another way?
$feature->image('image', 'your_crop_name', ['w' => 1000])
w => 1000 is just an examplew is sth like index?
It's width
you can pass any param supported by Glide
Quick reference - Glide
Wonderfully easy on-demand image manipulation library with an HTTP based API.
well...
$feature is one of features...
How are you saving this repeater?
Using a Feature model? Or a JSON column?
JSON repeaters do not support medias fields at the moment
I don't think we are using Feature model.
What do you have in the repository class of the module where you are using this inline repeater field?
Ok, so JSON repeater. You cannot use medias fields when saving a repeater using
$jsonRepeaters
. You should use $repeaters
in the repository, a features
hasMany relationship in your Location
model, pointing to a Feature model which uses HasMedias. That way you can use ->image like I said above. OR, if you don't want to deal with any of that, use a features
block in a block_editor
field. You won't have to create another model and deal with migrations etc...I see.
A lot of users are trying to use medias fields in JSON repeaters though, and we are going to look into it. Just so you know, the reason it is not supported is because we do not want to store a media reference in a model JSON column, we want all media references to be stored in the mediables table so we can know exactly where a specific image is being used in the content. I have an idea in mind to do that though, so we'll look into it.
Great!
And I have a problem with storing images.
it shows that content saved but after refresh, image is blank.
Yes, because JSON repeaters do not store attached medias. If you save it using an actual relationship it would work.
well... then what about this?
when I name the medias as 'hightlight' it shows the saved content but when I change name to anything like 'image' or 'images', it doesn't show the saved content.
And this is block...
I used this block inside of another model using Block Editor.
If you change the name after saving, that's expected. If not, it could be a conflict with other crop configurations in your project, but that shouldn't prevent saving and retrieving it.
well.. I only configured crop in twill.php.
inside of crops... I have 'highlight', is this something prevent me to name medias input other than 'highlight'?
no, it doesn't prevent it, but if you want to use something other than highlight, you should also define a key for that in the crops array
There is a default crop configuration if you use 'image' as the crop name, but most likely you need to apply your own configuration
so if we have 3 different Medias Name? then I should have 3 itmes in crops array?
yes, exactly. but you can reuse the same medias name across multiple blocks
That makes sense.
Thank you very much for your help.
So regarding features repeater, I need to create feature block and use it in location.
And do I need to use Block Editor? or is there other way that I can use feature block without Block Editor?
Yeah blocks are used within the block editor field. The only difference really with a repeater from a UX perspective is that if your block editor has a single possible block, the user needs to click twice instead of once to add an item (first on the add button then on the name of the block in the list). but like I said, we are looking into supporting medias fields in the repeater json column approach.
Okay, Sounds great!
So right now to use feature block, I have to create a new block.
And I have to insert Block Editor to Location.
Block Editor can add any block but how can I make Feature Block only available for that Block Editor?
'blocks' => [FeatureBlock::class]
on the block editor field