spatie / statamic-responsive-images

Responsive images for Statamic 3
MIT License
99 stars 29 forks source link

Passing a url does not work #132

Closed stuartcusackie closed 2 years ago

stuartcusackie commented 2 years ago

I'm not sure if this is a Blade-only problem but this is not working for me: @responsive('images/my-image.png', ['ratio' => '8/5'])

Neither is this: @responsive(asset('images/my-image.png'), ['ratio' => '8/5'])

Thanks!

riasvdv commented 2 years ago

Is this asset inside an asset container? You can't reference just any url of an image

stuartcusackie commented 2 years ago

oh! No problem then. Statamic's glide tag does allow any url so I assumed that this package allowed the same thing.

You might consider adding it, if possible. It can be useful sometimes. For example, if I have images that never change on site and I don't want to build global fields for them - It's easier just to reference images in my public folder.

I'm probably missing a reason why it wont work. No problem either way. I can workaround.

adevade commented 2 years ago

I'm trying to pass a relative URL to the Antlers tag, but can't get it working.

I'm defining some meta data directly in the yaml of the content file, without hooking it up to the CP. This is a standard page, with some extra one off content for this page only.

I have defined image: products/my-product.jpg, and want to pass this through the responsive tag. The image is already uploaded in an asset container and used in other places on the site.

I've tried {{ responsive:image }}, {{ responsive :src="image" }}, {{ responsive src="assets/{image}" }} but nothing seems to be working. It doesn't output anything.

Does it only work when the asset is defined as a field in a blueprint?


EDIT: Got it working!

In the content front matter:

-image: products/my-product.jpg
-image: /products/my-product.jpg
-image: assets/products/my-product.jpg
+image: /assets/products/my-product.jpg

(Must have leading slash, and relative from the public folder)

In the template:

{{ responsive:image }}
stuartcusackie commented 2 years ago

Just for my own reference, or anyone confused by this. You have to add your Laravel public folder as a Statamic asset container in order to use images located in your app/public folder, e.g.:

config/filesystems.php

'local_images' => [
  'driver' => 'local',
  'root'   => public_path() . '/images',
  'url' => env('APP_URL') . '/images',
  'visibility' => 'public',
],