Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

img_url / image_url inconsistency with broken image urls #1697

Open
twilson90 opened this issue Mar 8, 2023 · 6 comments
Open

img_url / image_url inconsistency with broken image urls #1697

twilson90 opened this issue Mar 8, 2023 · 6 comments

Comments

@twilson90
Copy link

A product without an image using the img_url filter:
{{ product | img_url }}

Outputs a valid image URL:
//cdn.shopify.com/shopifycloud/shopify/assets/no-image-100-c91dd4bdb56513f2cbf4fc15436ca35e9d4ecd014546c8d421b1aece861dfecf_small.gif

A product without an image using the image_url filter:
{{ product | image_url }}

Outputs the follow error:
[Liquid error (snippets/image line 8): invalid url input](http://127.0.0.1:9292/products/test) [test](http://127.0.0.1:9292/products/test)

Nobody wants to see an error with a line reference to the store's source code on a production store due to a bad image link. I can't think of any scenario where this behaviour would be preferable.
This also breaks any proceeding image_tag filter.
Is this a bug?

@maks-afew
Copy link

I ran into this issue when developing a new section. The workaround would be to first check if the image exists, and then loading it like this:

{% if image %}{{ image | image_url }}{% else %}whatever{% endif %}

But this is unnecessary ugly, new stuff shouldn't be less good than deprecated.
Not sure why return an exception, please fix

@sillycube
Copy link

sillycube commented Jun 14, 2023

I come across the issue today. Can it give a better output instead of the liquid error? I am following this example {{ product | image_url: width: 450 }}

I've tried the default filter but it doesn't work. This is ok: {%- if product.featured_image -%}"{{ product | image_url: width: 480 }}"{%- else -%}'abc'{%- endif %}

@naadeiii
Copy link

I'm experiencing the same issue when using image_url. img_url gets flagged by theme check, so I have to disable the check in this single repo.

Correct output:
{{ section.settings.image_right | img_url: 'master' }}
output: .../cdn/shop/files/banner-right.jpg?v=1688080442

Incorrect output:
{{ section.settings.image_right | image_url: 'master' }}
output: files/banner-right.jpg

@emmanuelizzy
Copy link

emmanuelizzy commented Dec 24, 2023

I'm experiencing the same issue when using image_url. img_url gets flagged by theme check, so I have to disable the check in this single repo.

Correct output: {{ section.settings.image_right | img_url: 'master' }} output: .../cdn/shop/files/banner-right.jpg?v=1688080442

Incorrect output: {{ section.settings.image_right | image_url: 'master' }} output: files/banner-right.jpg

How do you disable theme check, I'm trying to disable it for my project or find a way to update the default setting if there is an option.

I plan to update the tab size for schema JSON; the default is 2, but I'm a 4-space developer. Thanks.


By the way, I'm experiencing the same image_url issue where it returns files/banner-right.jpg while the img_url returns the URL as expected but we have a deprecated notice.


Edit
Solution: {{ section.settings.image_right | image_url }}.
The solution is removing the size flag and Shopify returns the image URL as expected.

@maks-afew
Copy link

Bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@sillycube @twilson90 @emmanuelizzy @naadeiii @maks-afew and others