Scottnj - When I add Medias::make()->name('main...
# ❓questions
s
When I add
Copy code
Medias::make()->name('main-image')
to a component block it creates the form field. I am able to select an image in the backend UI, but I cannot figure out how to get it to render for the frontend.
This is how I created the component block
Copy code
php artisan twill:make:componentBlock image
image.php
Copy code
use A17\Twill\Services\Forms\Fields\Input;
use A17\Twill\Services\Forms\Fields\Medias;
use A17\Twill\Services\Forms\Form;
use A17\Twill\View\Components\Blocks\TwillBlockComponent;
use Illuminate\Contracts\View\View;

class Image extends TwillBlockComponent
{
    public function render(): View
    {
        return view('components.twill.blocks.image');
    }
    public function getForm(): Form
    {
        return Form::make([
            Input::make()->name('title'),
            Medias::make()->name('main-image')
        ]);
    }
}
image.blade.php
Copy code
@if($block->hasImage('main-image'))
    <img src="{{ $block->image('main-image') }}" alt="{{ $block->imageAltText('main-image') }}" />
@else
    <p>Image not found</p>
    <pre>
        {{ dd($block->image('main-image')) }}
    </pre>
@endif
my result
Copy code
Image not found
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" // resources/views/components/twill/blocks/image.blade.php
i
hi @Scottnj is the image correctly saved in the cms? do you still see it in the block if you reload? if not, the reason is probably that you're missing a crop configuration for it. if you do have one, most likely your crop key isn't 'default' so you would need to call
$block->image('main-image', 'crop-key')
s
I was struggling with this all day. I finally got it to work. You were right, I wasn't using the crop keys correctly. Thank you again!