problem with asset_url?

by dv - Member - 10:09PM, Jun 29, 2008

Hi!
i’m trying to display an image using

{{'test.gif' | asset_url | img_tag, "Test1"}}

this expands to:

<img src="http://static1.shopify.com/s/files/1/0014/0332/assets/test.gif" alt="Test1" />

which isn’t the correct URL

if i hardcode using the URL given under assets->uploaded files->show original, like this

<img src="http://static0.shopify.com/s/files/1/0014/0332/files/test.gif" alt="Test1"/>

then it works correctly, but i don’t like the idea of hardcoding a lot of images.

Why doesn’t the the URL given by asset_url work?

rawsterne

Member

07:38AM, Jun 30, 2008

asset_url points to the assets inside your theme.

To see what I mean, login to your admin area, then click “Assets”. Now click “theme editor” and upload your test.gif file using the “upload new theme asset” link.

Now this bit of code will work:

{{'test.gif' | asset_url | img_tag, "Test1"}} 

Christina

Miss Manners

07:59AM, Jun 30, 2008

because there are different places where images are stored:

1) in a place called “theme assets” – here are the images that relate to the look of your shop. if you change the theme, they get deleted. this corresponds to the url:
http://static.shopify.com/s/files/1/shop/number/assets/image.gif
and the shortcut for that in liquid is asset_url
(where the segments /shop/number/ would be what it says: – /0014/0332/ for you.)

2) in a place called “uploaded files”. here are the images that relate to the content of your site, except for the product images. So these are the ones you upload when you enter a collection description, a blog entry picture, etc.
The url for this is http://static.shopify.com/s/files/1/shop/number/files/image.gif

There is no liquid shortcut to access these images, hence your problem.

3) on the product page – this is where you have all the product pictures. The url for this is http://static.shopify.com/s/files/1/shop/number/products/image.gif

The way I avoid hardcoding paths is this:

In my theme template, I enter the following code:
(you might need to put it in other templates too, depending on where you require these paths)

either this, which will give you relative paths:

{% assign themeassets = "/files/shops/shop/number/assets" %}
{% assign fileassets = "/files/shops/shop/number/files" %}

or this, which will give you absolute paths.

{% assign themeassets = "http://static.jadedpixel.com/s/files/1/shop/number/assets" %}
{% assign fileassets = "http://static.jadedpixel.com/s/files/1/shop/number/files" %}

I don’t know which of these two options is the better, maybe someone else can tell us. Paul would probably know.

then you can use the following paths:

<image src="{{themeassets}}/image.gif" alt="image" />
<image src="{{fileassets}}/image.gif" alt="image" />

---

operation absurdist feature requests: terminated

(http://en.wikipedia.org/wiki/Absurdism)

dv

Member

12:33PM, Jun 30, 2008

thanks, exactly what i needed :)

You must login to post a comment!

Don't have an account yet? Sign up for one.