Scott
Scott

Reputation: 1310

Handlebars single quote issue

I'm having difficulty processing an onclick event where paramater values are passed through to a custom function via handlebars. I've also tried to escape the quotes and use triple brackets {{{Surname}}}}

The following will break if the surname is: O'Neill

{{#each employee}}
    <div onclick="populateForm('{{Firstname}}', '{{Surname}}');">test for {{Firstname}} {{Surname}}</div>
{{/each}}

I've tried various combinations of single and double quotes to build my event handler but can't get this to work.

thanks

Upvotes: 2

Views: 3447

Answers (1)

Gibin Ealias
Gibin Ealias

Reputation: 2859

Along with single and double quotes, you can also use the Acute character (`) in your statement.

The below Handlebars code works fine,

{{#each employee}}
    <div onclick="alert(`{{{Firstname}}}`, `{{Surname}}`);">test for {{{Firstname}}} {{Surname}}</div>
{{/each}}

with this sample JSON

{
  "employee": [
    {
      "Firstname": "a",
      "Surname": "b"
    },
    {
      "Firstname": "o'neill",
      "Surname": "d"
    }
  ]
}

Tested using http://tryhandlebarsjs.com. Hope this helps.

Upvotes: 2

Related Questions