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

[Question] Help understanding the indent built-in #917

Open
apiraino opened this issue May 18, 2024 · 0 comments
Open

[Question] Help understanding the indent built-in #917

apiraino opened this issue May 18, 2024 · 0 comments

Comments

@apiraino
Copy link

I am looking at the new indent built-in introduces recently (merged in #798).

At first I was looking into slightly clarifying the documentation wording, see docs, but then went down this rabbit hole and found myself confused on how to use it.

Example main.rs:

use tera::{Context, Tera}; // v1.19.1

fn main() {
    let context = Context::new();
    let tera = Tera::new("./*.tt").unwrap();
    let res = tera.render("test.tt", &context).unwrap();
    println!("{}", res);
}

Tera template test.tt:

// testing `prefix`
-{{ "TEXT" | indent(prefix="") }}
-{{ "TEXT" | indent(prefix="    ") }}

// testing `first`
-{{ "one\n\ntwo\nthree" | indent }}
-{{ "one\n\ntwo\nthree" | indent(first=true) }}

// testing `blank`
-{{ "   ABCD" | indent(blank=true) }}
-{{ "   ABCD" | indent(blank=false) }}
-{{ "   " | indent(blank=false) }}
-{{ "   " | indent(blank=true) }}

Will be rendered as:

// testing `prefix`
-TEXT
-TEXT

// testing `first`
-one\n\ntwo\nthree
-    one\n\ntwo\nthree

// testing `blank`
-   ABCD
-   ABCD
-   
-

Question for @untereiner (author of the #798 ): can you help me understand how the flags blank,first and prefix actually work? The above template rendering is slightly confusing for me.

Thanks!

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

1 participant