Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register a function in Tera #2493

Open
MaoHolden opened this issue May 8, 2024 · 5 comments
Open

Register a function in Tera #2493

MaoHolden opened this issue May 8, 2024 · 5 comments

Comments

@MaoHolden
Copy link

Register a Tera function in order to execute complex logic like calculating read time.

Summary

Zola uses the Tera engine, I would like to calculate the read time of my markdown posts. One way I thing it could be done is by adding a Rust function in the Tera engine using tera.register_function but I don't see how this can be done in the documentation.

Proposed solution

Either specify that its not possible yet or document how.

Greetings

Thank you for the great framework 🤩.

@Keats
Copy link
Collaborator

Keats commented May 8, 2024

It's not possible currently. For the next version of Tera, i'm thinking of allowing some scripting language like https://rhai.rs/ or wasm functions. Not coming anytime soon though.

@MaoHolden
Copy link
Author

Got it, sounds like a cool idea :). I was checking the docs I the only place I see to put a comment about this is in /documentation/templates/overview/. You reckon its useful or just with this Issue is enough?

@Keats
Copy link
Collaborator

Keats commented May 9, 2024

Note that for this specific feature we do have a very crude version. See reading_time in https://www.getzola.org/documentation/templates/pages-sections/
Was it for a non latin language?

@MaoHolden
Copy link
Author

Yeah I'm using that already :). Thanks!.

Also if you want I could make a PR with a small comment about not having support for registering custom functions to Tera. If you don't think its necessary you can just close the Issue 🙂

@Keats
Copy link
Collaborator

Keats commented May 10, 2024

sure but I think right now it's implicit it's not supported. It wouldn't hurt to write it int he docs though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants