Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Dynamic asset names #625

Closed
wrozka opened this issue Jun 6, 2018 · 8 comments
Closed

Dynamic asset names #625

wrozka opened this issue Jun 6, 2018 · 8 comments
Assignees

Comments

@wrozka
Copy link

wrozka commented Jun 6, 2018

Problem

I'm using a liquid template to generate img tags with srcsets. Referenced images give 404. It stopped working after upgrading to 1.x

Replication steps

It works fine with static name:

<img src="{{  '../assets/images/b.jpg'  | asset_url }}">

It doesn't work if the images is referenced by a variable. It returns 404 on localhost and it doesn't get copied to dist/assets.

{% assign b = '../assets/images/b.jpg' %}
<img src="{{ b | asset_url }}">

More Information

I'm using slate-tools 1.0.0-beta.2

@t-kelly
Copy link
Contributor

t-kelly commented Jun 18, 2018

This might eventually be possible when Slate can properly parse Liquid

@wrozka
Copy link
Author

wrozka commented Jun 19, 2018

@t-kelly I migrated my theme to 1.x to enable React, ES6 and other build tools, and it was super to enable JSX transformation, etc. But this a really big issue for me, as I cannot use my old liquid templates. Is there any workaround besides inlining all the variables? Is it possible to generate asset_urls during the build?

@t-kelly
Copy link
Contributor

t-kelly commented Jun 19, 2018

Is it possible to generate asset_urls during the build?

Yes it's possible, but to do so we need to be able to properly parse Liquid off of Shopify servers. This will take some time to accomplish and needs to be prioritized with the rest of Slate's backlog.

@wrozka
Copy link
Author

wrozka commented Jun 26, 2018

Thanks. Is it possible to generate asset urls without liquid? I want to use them in react components.

@t-kelly
Copy link
Contributor

t-kelly commented Jun 26, 2018

No you need Liquid. In the past, we have typically access Liquid values with JS by declaring the values we need on a global JS variable. For example in the main layout file we declare:

<script>
var liquidData = {
  myValue: {{ product.image | asset_url }}
}
</script>

@wrozka
Copy link
Author

wrozka commented Jun 27, 2018

Ok, thanks!

@t-kelly t-kelly self-assigned this Oct 15, 2018
@t-kelly t-kelly mentioned this issue Oct 22, 2018
6 tasks
@t-kelly
Copy link
Contributor

t-kelly commented Oct 25, 2018

@t-kelly t-kelly closed this as completed Oct 25, 2018
@lock
Copy link

lock bot commented Nov 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants