Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine
MIT License
1.25k stars 216 forks source link

Expose parse/parseWithoutProcessing in the IHandlebars interface #369

Open oformaniuk opened 3 years ago

oformaniuk commented 3 years ago

Original issue: zjklee/Handlebars.CSharp/issues/27

This would be very useful to allow a user to extract the tokens from a template and then be able to extract the variables required for a particular template. The feature of extracting the variables was requested long ago here in the native handlebars.js and ultimately is what I would love to see implemented as well.

https://github.com/handlebars-lang/handlebars.js/issues/1207

Currently there is no way to have the compiler parse the template for tokens and simply return the results in the interface. The compiler and applicable helpers are internal classes / methods so there is no good way to extract this information now.

Alternatively, simply exposing all the variable names required by a template would be the best but this is not currently available in the handlerbars lang.

The handlebars api has methods to parse and parseWithoutProcessing returning the ast/tokens.

https://github.com/handlebars-lang/handlebars.js/blob/master/docs/compiler-api.md

mythjuha commented 2 years ago

Would love to see this feature as well. Especially when creating new templates i'd be nice to extract an anonymous 'data object' you can then use to test/try-out your template with on the fly values.

knightmeister commented 1 year ago

+1 for this issue, would be very useful