tera icon indicating copy to clipboard operation
tera copied to clipboard

Unable to concatenate in extends template name

Open vincent-herlemont opened this issue 4 years ago • 3 comments

We can't concatenate in extends template name.

The following code doesn't work.

{% extends variable ~ "my_template" %}

And this error is thrown:

Template '<template name>' not found
Full example here (rust code):
use tera::Tera;
let mut context = tera::Context::new();
context.insert("MY_VARIABLE", "value");
let mut tera = Tera::default();

tera.add_raw_template(
   "value_template_1",
   r#"block: {% block number %}1{% endblock %}"#,
);

tera.add_raw_template(
   "template_2",
   r#"{% extends MY_VARIABLE ~ "template_1" %}
   {% block number %}2{% endblock %}"#,
);

let out = match tera.render("template_2", &context) {
    Ok(content) => content,
    Err(error) => {
           eprintln!("{}", error);
           return;
      }
};
println!("{}", out);

vincent-herlemont avatar Aug 03 '21 12:08 vincent-herlemont

This is not supported, only plain strings are allowed (eg {% extends "my_template" %}) so we can rule out inheritance errors at compile time.

Keats avatar Aug 03 '21 13:08 Keats

Did you plan to support this feature in a further release?

vincent-herlemont avatar Aug 09 '21 14:08 vincent-herlemont

No

Keats avatar Aug 09 '21 15:08 Keats