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

how to get each helper length? #420

Closed
wzhsh90 opened this issue Mar 3, 2021 · 2 comments · Fixed by #421
Closed

how to get each helper length? #420

wzhsh90 opened this issue Mar 3, 2021 · 2 comments · Fixed by #421
Assignees

Comments

@wzhsh90
Copy link

wzhsh90 commented Mar 3, 2021

{{#each list}}

{{/each}}

how to get list's length ?

the follow code is wrong
{{#if (gte list.len() 0)}}

{{/if}}

@123shang60
Copy link

The length in handlerbars-rust syntax is not supported

example:

use handlebars::Handlebars;
#[macro_use]
extern crate serde_json;

fn main() {
    let mut h = Handlebars::new();
    h.register_template_string("1",r#"
    {{foo.length}}
    "#).unwrap();
    let res = h.render("1", &json!({"foo": ["1","2"]})).unwrap();
    println!("{}",res);
}

Compile and run the application, and you can get the response:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: RenderError { desc: "Error on accessing array/vector with string index.: invalid digit found in string", template_name: Some("1"), line_no: Some(2), column_no: Some(5), cause: Some(ParseIntError { kind: InvalidDigit }) }', src/main.rs:10:57

@sunng87
Copy link
Owner

sunng87 commented Mar 4, 2021

Yes. You will need a helper for this. I will create a built-in helper to fill the gap.

@sunng87 sunng87 self-assigned this Mar 4, 2021
@sunng87 sunng87 mentioned this issue Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants