mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)

Home Page:https://mozilla.github.io/nunjucks/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Extract required context variables from template string

alex-statsig opened this issue · comments

I'm building an internal tool to help teams quickly plug variables into an arbitrary nunjucks template and render it (we're using it to generate SQL queries). It would be nice if there was a way to extract the required variables (either through all codepaths are at least through the executed path of a given "render" call) so we can provide them with a list of variables to fill in. I have a rough heuristic with some regex (templateStr.matchAll(/{{\s*([a-zA-Z0-9_]+)\s*}}/g))) but it misses anything other than simple context references. I tried using a proxy object into renderString() but it seems because of the way its loaded (via first storing into a map rather than accessing as needed) this doesn't help.

hey, can I work on this issue