Skip to content

If lookup with parenthesis causes error #541

@Nutomic

Description

@Nutomic

I was surprised by the following code throwing an error:

let mut reg = Handlebars::new();
reg.set_strict_mode(true);

// register template using given name
reg.register_template_string("tpl_1", "hello {{#if (lookup my_vec 1)}}some{{else}}none{{/if}}")?;
let my_vec = vec![Some(1), None];
println!("{}", reg.render("tpl_1", &json!({"my_vec": my_vec}))?);
Ok(())

Error: RenderError { desc: "Value is missing in strict mode", template_name: Some("tpl_1"), line_no: Some(1), column_no: Some(7), cause: None, unimplemented: false }

There are two ways to fix it. Either disable strict mode, or replace template string with the following (note removed parenthesis inside if).

reg.register_template_string("tpl_1", "hello {{#if lookup my_vec 1}}some{{else}}none{{/if}}")?;

I would expect the original code to work, based on handlebars docs.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions