rwf2 / Rocket

A web framework for Rust.
https://rocket.rs
Other
24.34k stars 1.56k forks source link

Cannot use Tera's template inheritance #495

Closed paulvt closed 6 years ago

paulvt commented 6 years ago

If one is using Tera templates and there is any template that extends another, Rocket's launch fails throwing the following launch error:

Error: Failed to initialize Tera templating.
    => Template 'index' is inheriting from 'base.tera', which doesn't exist or isn't loaded.
Error: Rocket failed to launch due to a failing fairing.
thread 'main' panicked at 'launch fairing failure', 

This error is thrown regardless of whether I am using any of the templates, so it probably has to do with the way the fairing is loading them?

Template inheritance is very useful for having several layouts/blocks and extended them to create page templates. See also: https://tera.netlify.com/docs/templates/#inheritance.

I am using Rocket (codege/contrib) 0.3.3 on Debian GNU/Linux testing.

SergioBenitez commented 6 years ago

It looks like you're asking for a template named "base.tera"; this would mean that you have a file named something like "base.tera.tera", which seems unlikely. You'll likely be able to resolve this by simply changing "base.tera" to "base".

paulvt commented 6 years ago

@That results in:

    => Template 'index' is inheriting from 'base', which doesn't exist or isn't loaded.

So, unfortunately, that doesn't help. I was a bit confused by Tera just using index.html but Rocket (logically) insisting on the .tera extension because it needs to know what to do.

SergioBenitez commented 6 years ago

Without seeing your file system layout, I don't know what things should be called. Please see the tera templates examples for a concrete implementation.

paulvt commented 6 years ago

When using .html.tera as extension as opposed to just .tera, everything works fine! Thanks!

I followed the guide on templating here, so it was not clear to me that a render of index means index.html.tera should exist. Maybe a note could be added or the explanation on extensions could be tweaked? (I overlooked the tera template example, sorry).