How to parse all outputs from template string? #528
Replies: 3 comments 2 replies
-
There is a way, but now there's no AST definition, that means the way to access the parsed tokens is implementation specific and subject to change. For example the following code outputs what you mentioned above: const { Liquid } = require('liquidjs')
const engine = new Liquid()
const tpls = engine.parse(`
{{bucket}}
{% for product in products %}
{{ product.name }} ads
{% endfor %}
`)
console.log(tpls[1].token.content) // outputs: bucket
console.log(tpls[3].impl.templates[1].token.content) // outputs: product.name Note that the name I'm planning to provide a well-defined AST in the next major version (latter this year). Just created this work item to remind me: https://github.com/harttle/liquidjs/projects/1#card-84455385 |
Beta Was this translation helpful? Give feedback.
-
Hm. I still don't understand how can I know specific indexes of array's elements? Imagine I have big complex template. How can I grab outputs? |
Beta Was this translation helpful? Give feedback.
-
In v10, I consolidated property names refering to child templates and created a demo for iterating templates. Sorry I forgot to update this thread after released v10. Here's the demo entry point to get all outputs: https://github.com/harttle/liquidjs/blob/master/demo/template/index.ts The most important part is: liquidjs/demo/template/get-outputs.ts Lines 8 to 24 in 7526d40 |
Beta Was this translation helpful? Give feedback.
-
Hello.
I need to parse all outputs from template.
So I want to get array like
["bucket", "product.name"]
or something like that.How can I do it?
Beta Was this translation helpful? Give feedback.
All reactions