Expose the template ast - #59
Conversation
Sometimes a consumer of a template needs to know what objects were used. In my case, a template can reference secret values from a secret store vault and instead of passing all possible secrets to the template only to render two of them, we use the ast to determine which are used and only retrieve those values from the vault before rendering the template. Exposing the ast allows us to use the liquid APIs just like normal, without having to jump through hoops to build the ast ourselves using the other types exported in this library. Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
|
Thank you for your contribution! Do you have example code where you use this? If so, I would like to add a link to this in the documentation; it sounds like it could be useful material for users of this package. |
|
How about I make a small godoc example and submit a PR so that it's easy to find? We are using it in Porter, so that we can determine which secrets to retrieve from vault and inject back into the config file but I think it would be easier to understand without all the extra Porter stuff going on. Here's where we load our template and switch to using different delimiters (I'm so glad you support that!) Here's where we parse the ast in the template and grab out any variables used: |
Updated CHANGELOG.md to include all merged PRs since version 1.3.0 (2020-02-13): Added features: - Jekyll Extensions Support (#114) - Auto-Escape Feature (#111) - Template Loader (#107) - BasicEngine (#104) - JSON Filter (#84) - Strict Variables Mode (#74) - Custom Writer Support (#86) - Template AST Access (#59, #66) - For-Else Support (#93) - Unless-Else Support (#68) - General Range Expressions (#65) - Loop Modifier Expressions (#67) Fixes: - Size filter, slice bounds, division by zero - Nil pointer handling - Whitespace control - Multiline slice - Block errors - Map filter with structs - And more Also added steve-ky as contributor for ideas/feedback on PR #89. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Sometimes a consumer of a template needs to know what objects were used. In my case, a template can reference secret values from a secret store vault and instead of passing all possible secrets to the template only to render two of them, we use the ast to determine which are used and only retrieve those values from the vault before rendering the template.
Exposing the ast allows us to use the liquid APIs just like normal, without having to jump through hoops to build the ast ourselves using the other types exported in this library.
Checklist
make testpasses.make lintpasses.