Nunjucks: Access variables

Created on 11 Apr 2017  路  4Comments  路  Source: mozilla/nunjucks

This might be a stupid question but is it possible to get a list of all the variables in a template?

Most helpful comment

+1 This would be useful for me.

All 4 comments

Unfortunately it isn't possible right now.

Though, it is possible to do in Jinja2, related issue can be found here #973. Maybe one day Nunjucks will get that feature too.

After looking at the code, I think it's possible to do what I need. I simply need to build something to traverse the ast and return only the variables.

var c = new Compiler();
var src = 'hello {% filter title %}' +
    'Hello madam how are you' +
    '{% endfilter %}'
var ast = transformer.transform(parser.parse(src));
// nodes.printNodes(ast);

If you will come up with working solution, don't forget to post it here :) I think to some people it might be useful.

+1 This would be useful for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sudhirbeldar picture sudhirbeldar  路  3Comments

dgirgenti picture dgirgenti  路  3Comments

popomore picture popomore  路  6Comments

gaboesquivel picture gaboesquivel  路  4Comments

ricordisamoa picture ricordisamoa  路  5Comments