Liquid tags inside of scope object #541
zettk
started this conversation in
Working with Express
Replies: 1 comment
-
You can register a filter for this, but the template string need to be changed to call the filter. const liquidjs = require("liquidjs");
const template = 'Hello {{myValue | render}}';
const engine = new liquidjs.Liquid()
engine.registerFilter('render', function (tpl) {
return engine.parseAndRender(tpl, this.context.getAll())
})
engine
.parseAndRender(template, {myValue: 'world {{myOtherValue}}', myOtherValue:'its liquid'})
.then(html => console.log(html)) In the above example, a filter named Performance wise, if the same string can be rendered again and again, you can:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello all,
We are trying to use liquid in our project.
However, the thing I can not get my head around is if is possible to pass a liquid into the template from scope?
e.g. let assume I am calling the function "parseAndRender" with parameters template (our html with liquid tags and filters) and scope as JSON with the personalization values.
If the JSON would contain a string value which contains outputs or tags. Is there a way how to execute them?
Please see the snippet below:
==================
========================================
Current output
Hello world {{myOtherValue}}
Wanted output
Hello world its liquid'
The use case is that the final output is based on data coming from several places and hence we would like to store the reference to those objects as liquid tags/outputs in between the sources.
Such as in our example we do not store the currency of products in product catalogue on the product level, but on the e-store level.
Hence we would prefer to store in the product record only reference to the path of the object in which the currency field is stored for example: {{estore.currency}} and populate the value from the estore object during the rendering.
Beta Was this translation helpful? Give feedback.
All reactions