osteele / liquid

A Liquid template engine in Go
https://godoc.org/github.com/osteele/liquid
MIT License
287 stars 59 forks source link

Example: List variables used in template #62

Closed carolynvs closed 2 years ago

carolynvs commented 2 years ago

Add a godoc example that demonstrates how to list variable names used.

I realized when I wrote this example that it works great for us since we don't use expressions in templates like {{ myvar | capitalize }}. It doesn't work for expressions but it could if I exported a few more values so that I can get the bindings used in the expression context.

I can submit a PR to add a few more getter functions to make this example work for more templates if that's something you would consider merging?

Below is a screenshot of the example rendered in godoc

Screen Shot 2022-02-13 at 9 08 59 PM

Checklist

carolynvs commented 2 years ago

@osteele I'm leaving this in draft because without extra changes this example only works in limited scenarios and probably isn't something you want to include in your godocs.

carolynvs commented 2 years ago

Closing since after spending all afternoon trying to figure out how to get the info I need out of the expression closures, I am not sure this is something I can contribute right now.

osteele commented 2 years ago

Thank you for the effort. If you are able to leave some notes about what information you are trying to get out of the expression closures, I can take a look at it when I get a chance. But I also am familiar with how much work it can be to try to write up something like that, and I can't guarantee I'll be able to find a solution, so please don't feel any obligation.