tera icon indicating copy to clipboard operation
tera copied to clipboard

Can 'default' filter use after 'default' filter?

Open XyLyXyRR opened this issue 3 years ago • 2 comments

Hi, there.

use std::error::Error;
use tera::{Context, Tera};

type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;

fn main() -> Result<()> {
let context = {
let mut context = Context::new();
context.insert("name", "");
context.insert("desc", "");
context
};
let tpl = r###"{%- set text = name | default(value=desc) | default(value="default") -%}
{{ text }}"###;
println!("{}", Tera::one_off(tpl, &context, false)?);
Ok(())
}

I want tera output default, but it output nothing. Is there another way to do this? Or this will work in tera 2?

XyLyXyRR avatar Mar 26 '21 10:03 XyLyXyRR

Does something like let tpl = r###"{%- set text = name | default(value=desc or "default") -%} work?

Keats avatar Mar 27 '21 07:03 Keats

No.

XyLyXyRR avatar Mar 27 '21 08:03 XyLyXyRR