We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Is there a way to deliver the data to the liquid file?

Solved

Is there a way to deliver the data to the liquid file?

help_me
Shopify Partner
12 0 1

Hello
I just created a page using the app proxy and is there a way to deliver data to that page?


help_me_0-1675058155347.png

 

Like the code above, we are loading the liquid file using express.
And I want to hand over the data to the liquid file.

For example, when accessing the /front/view/:id path, you want to pass the ":id" value to the "view.liquid" file.

 

If there is no way to transfer data to liquid files, How can I write a value like ":id" in a liquid file?

Accepted Solution (1)

Not applicable

This is an accepted solution.

Hi @help_me,

 

So you've created an app proxy URL and you're now serving up a liquid file. Great! Now you want to pass data server side to that file...

 

First set the header content-type to "application/liquid"

 

 

 

 res.set({
   "content-type": "application/liquid"
 });

 

 

 

Next, serve the file along with data:

 

 

 

const {id} = req.params;

res.render('client', {
  id: id
});

 

 

 

You'll also want to save view.liquid as view.ejs 

 

Finally in your view.ejs, display that data or use in a script:

 

<script>
var id = {{ id }};
</script>


<h1>Your ID: {{ id }}</h1>

 

Best,

Sam - Owner/Lead Developer 

Achieve Applabs 

View solution in original post

Replies 4 (4)

Not applicable

This is an accepted solution.

Hi @help_me,

 

So you've created an app proxy URL and you're now serving up a liquid file. Great! Now you want to pass data server side to that file...

 

First set the header content-type to "application/liquid"

 

 

 

 res.set({
   "content-type": "application/liquid"
 });

 

 

 

Next, serve the file along with data:

 

 

 

const {id} = req.params;

res.render('client', {
  id: id
});

 

 

 

You'll also want to save view.liquid as view.ejs 

 

Finally in your view.ejs, display that data or use in a script:

 

<script>
var id = {{ id }};
</script>


<h1>Your ID: {{ id }}</h1>

 

Best,

Sam - Owner/Lead Developer 

Achieve Applabs 

help_me
Shopify Partner
12 0 1

Thank you!
But there's one problem.
<h1>Your ID: {{ id }}</h1> The id value does not come out with this code, but the id value is exposed only if you write it like this <%= id %>.
{{ id }} Is there any way to do it this way?

Not applicable

Hi @help_me,

 

Right, the default template engine on Node is EJS.

 

Change your templating engine to Liquid on your express server. Here's a good tutorial: https://liquidjs.com/tutorials/use-in-expressjs.html

Best,

Sam

help_me
Shopify Partner
12 0 1

hi @Anonymous 

 

Thank you for telling me a good way.
However, if you change the engine to liquid as you told me, the style or metafields are not working.

Is there any way to use liquid grammar well while handing over data from express?