s.kuznetsov
s.kuznetsov

Reputation: 15213

how to get the url only in javascript shopify

I have a metafield of type document, and in the ajax query I get the value of this field as

"gid://shopify/GenericFile/31146481287411"

I need the url. I can easily get that url in liquid using file_url:

{{ metafields.custom.document | file_url }}

But I need to get the url specifically in javascript!

Please tell me how I can do this, and is there a workaround? Thank you.

Upvotes: 1

Views: 572

Answers (1)

David Lazar
David Lazar

Reputation: 11427

Store the file url in a string metafield, and get that instead of the GID to a resource. Alternatively, since your JS has to run AFTER Liquid rendering, render the URL into a JS variable and use it as you wish. You have plenty of options.

Upvotes: 1

Related Questions