Keats / tera

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

Macro fails to be defined at top of template file #821

Closed sdedovic closed 10 months ago

sdedovic commented 1 year ago

I believe this is related to a few other issues but here is the behaviour I have noticed:

Issue 1 - Using a macro in the same template where it is defined

{% macro input(label, type="text") %}
    <label>
        {{ label }}
        <input type="{{type}}" />
    </label>
{% endmacro input %}

<div>
{{ self::input(label="Name", type="text") }}
</div>

and try to render it, src/main.rs

fn main() -> Result<()> {
    let tera = Tera::new("templates/**/*.html")?;
    println!("{:#?}", tera.render("test.html", &Context::default())?);
}

it will successfully compile the template but error out when rendering it due to the macro definition console

$ cargo run

Error: Failed to render 'test.html'

Caused by:
    Invalid macro definition: `input`