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

signle quote not working #470

Closed
theowenyoung opened this issue Sep 29, 2021 · 10 comments · Fixed by #475
Closed

signle quote not working #470

theowenyoung opened this issue Sep 29, 2021 · 10 comments · Fixed by #475

Comments

@theowenyoung
Copy link

Test:

    #[test]
    fn test_template() {
        let mut handlebars = Handlebars::new();
        let data = json!({});
        handlebars.render_template("{{'test'}}", &data).unwrap();
    }

Throw,

---- test::test_template stdout ----
thread 'test::test_template' panicked at 'called `Result::unwrap()` on an `Err` value: RenderError { desc: "Failed to parse template.", template_name: None, line_no: None, column_no: None, cause: Some(TemplateError { reason: InvalidSyntax, template_name: None, line_no: Some(1), column_no: Some(3), segment: Some("   0 | {{'test'}}\n     |---^------\n") }), unimplemented: false }', src/main.rs:155:57
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@sunng87
Copy link
Owner

sunng87 commented Sep 29, 2021

Single quote is not supported for now. Is there any workaround for your scenario?

@theowenyoung
Copy link
Author

Thanks for your replay!

I want use a helper: like <html lang="{{first_non_empty lang 'en'}}">

but I tried <html lang="{{first_non_empty lang 'en'}}">, <html lang="{{first_non_empty lang [en]}}">, <html lang="{{first_non_empty lang \"en\"}}">, neither of them can work.

Am I missed anything?

@theowenyoung
Copy link
Author

theowenyoung commented Sep 29, 2021

@sunng87
Copy link
Owner

sunng87 commented Sep 29, 2021

@theowenyoung have you checked if <html lang="{{first_non_empty lang "en"}}"> works for you?

@theowenyoung
Copy link
Author

Thanks... surprise... it just works!

I never try it.

Thanks again!

@beltram
Copy link

beltram commented Nov 15, 2021

Hi,

using single quotes actually works up to version 3.5.3. It starts failing with this commit introduced in 3.5.4.

With my usage of handlebars, I must cope with a specification enforcing the usage of single quotes e.g. {{now offset='3 days'}}. It would be awesome to have single quote support back so that I could benefit from the improvements in the latest versions.

@sunng87 WDYT should we re-open this one ?

@sunng87
Copy link
Owner

sunng87 commented Nov 16, 2021

@beltram Thank you for investigation and we can reopen this.

@sunng87
Copy link
Owner

sunng87 commented Nov 16, 2021

@beltram It should be fixed in #475. Could you please verify if the current master branch work you? I can create a release tomorrow if it's ok

@beltram
Copy link

beltram commented Nov 16, 2021

@sunng87 indeed #475 works and fixes the issue. Thank you very much !

@sunng87
Copy link
Owner

sunng87 commented Nov 18, 2021

@beltram the fix was released in 4.1.5

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

Successfully merging a pull request may close this issue.

3 participants