Replies: 5 comments
-
AFAIK, no. I assume you need top level names. But names can be nested in scopes and builtin drops like in for tag. And can be dynamic. I would like to implement one if it can be clearly defined and still useful. |
Beta Was this translation helpful? Give feedback.
-
yes, just top level static variable names would be sufficient for my use case. I see your point about dynamic variables though. I wrote this very hacky method: const _extractTemplateVars = function (parsedTemplate) {
const variables = new Set();
function traverseTokens (tokens) {
for (const token of tokens) {
if (token.token.constructor.name === 'OutputToken') {
for (let p of token.value?.initial?.postfix) {
let prop = p.props[0];
if (prop.constructor.name === 'IdentifierToken') {
variables.add(prop.content);
}
}
}
else if (token.token.constructor.name === 'TagToken') {
for (let branch of token.branches) {
traverseTokens(branch.templates);
}
}
}
}
traverseTokens(parsedTemplate);
return variables ;
} |
Beta Was this translation helpful? Give feedback.
-
Seems like there is something like this being worked on in the ruby version? |
Beta Was this translation helpful? Give feedback.
-
HI @amit777 , any leads on this, i am also facing the same requirement. @harttle can we have functionality from liquid which gives list of all the tags being used in the template ? All the variables be it dynamic ones or in nested scopes.Will really appreciate this functionality if released . Thanks |
Beta Was this translation helpful? Give feedback.
-
On our side we would also need something like this because we want to be able to call our backend to fetch only the data that was really used in the template, so we don't have to pull on all of our micro-services when the template only requires the first name of an account. One example: I would like to be able to retrieve either an list with all variable
or an object like this:
|
Beta Was this translation helpful? Give feedback.
-
Hi, we need to do some validation in our code regarding the names of parameters within a liquid template. Ideally I would like to do something like
Is there an easy way to do this?
Beta Was this translation helpful? Give feedback.
All reactions