Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As someone who spent way too much time building Django inspired template engines (Jinja, Jinja2, Twig, etc.) I must say this is really cool and very close to what I wanted to build myself for Rust but did not have the time.

> Tera uses serde which means that in the example above

Very good. But serde needs to get stable :(

> beautiful html output out of the box (ie no need for the {{- tags)

This is a request that comes up often but I tested this so much and always came back to not doing magic. It breaks too many applications in unintended ways (particularly plain text output).

> able to register new tags easily like the {% url ... %} in Django

I would not do that again. Jinja has an extension interface and I regret adding it. I much rather have people just expose functions to the templates. That said, in Rust that might be not a good idea because there are no keyword arguments so make it makes sense there.

> no macros or other complex logic in the template […] include partial templates

Another thing i strongly disagree with but I can see the motivation. Macros in Jinja I prefer so much over includes because it becomes clear what values exist. Includes become really messy unless you are very organized. Macros (which are just functions) accept the parameters and it becomes clear what the thing does. Just look at that macro as an example: https://github.com/pallets/website/blob/master/templates/mac...

It's absolutely clear what it accepts as parameters. If that was a partial include the "caller" needs to set up the variables appropriately and there is no clear documentation on what the template wants etc.

But awesome to see this happen for Rust!



> Very good. But serde needs to get stable :(

I agree :(

> This is a request that comes up often but I tested this so much and always came back to not doing magic. It breaks too many applications in unintended ways (particularly plain text output).

That was even the first feature request I got. I don't think I'll go more into magic than what it currently is, seems to be okay-ish

> I would not do that again. Jinja has an extension interface and I regret adding it. I much rather have people just expose functions to the templates. That said, in Rust that might be not a good idea because there are no keyword arguments so make it makes sense there.

That was my first thought on a better way to do template tags but not sure how to do that in Rust. If anyone has an idea, there's https://github.com/Keats/tera/issues/23 now

Good point about macros, maybe I can have a look later. Macros and include feel like they fill the same spot in my mind in terms of features so I'd rather not have both.


> Good point about macros, maybe I can have a look later. Macros and include feel like they fill the same spot in my mind in terms of features so I'd rather not have both.

You could always repurpose includes as imports, i.e. not generate any output from imports, but to allow their use as purely an organizational tool for importing macros.


> Jinja has an extension interface and I regret adding it. I much rather have people just expose functions to the templates.

So, like Ruby's ERB, where you're passing a lexical binding? Or is that going a bit too far? (It's always felt a bit "magic" to me, but—imagining a version of ERB that compiled its templates to modules—the magic would basically have to be discarded at compile-time and turned into regular hash-lookups in order to get something with a sane runtime API anyway. So it'd be the "funny macro" kind of magic rather than the "bunch of runtime introspection" kind of magic.)


For the record, that's how Play's Twirl templates work. Templates are compiled (at compile time) to plain Scala singletons with an entry point method that builds the output.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: