How is get information about product and id page from storefront API JS?

Tourist
6 0 0

I am developing an app for the marketplace and I included js file to the storefront.
How can I understand what the page is it? And if this page is === "product", then how can I get the information about a product.

I checked documentation and git repository with examples https://github.com/Shopify/storefront-api-examples
And I didn't find an answer.

0 Likes
Shopify Partner
390 12 36

Hey there,

 

You can add a code snippet in, say, theme.liquid that would output page template name as a JavaScript variable on the server side so it is available for your client side code. Something like:

<script type="text/javascript">
  var page = '{{template.name}}';
</script>
CTO, Co-founder of nemo.ai
0 Likes
Highlighted
Tourist
6 0 0

How is liquid work? How include liquid in js file?
Thank you.

0 Likes
Tourist
6 0 0

ping

0 Likes