Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.56k stars 285 forks source link

how do i register a function? #733

Open Directory opened 2 years ago

Directory commented 2 years ago

https://tera.netlify.app/docs/#functions

the docs seem outdated. this isnt valid rust i dont think.

Keats commented 2 years ago

You can have a look at https://github.com/Keats/tera/blob/master/src/builtins/functions.rs for some examples of built-in functions

Directory commented 2 years ago

after figuring it out ill update this issue with how instead the documentation is very vague and bad. How should anyone know that the Result type is a special wrapper and not built in. whats the Function type from? How was anyone supposed to know that serde_json is used here. The example code should be updated with all necessary imports that it uses. Additionally i think it would be a better example if instead it was a tera::Function implementation on an empty struct rather than a function that returns a Box. Considering how awful this documentation was theres probably other awful code examples in the rest of the docs.

Keats commented 2 years ago

Sorry for the awful documentation. Have you seen the awful API documentation as well on https://docs.rs/tera/latest/tera/trait.Function.html? That should answer some of your questions.