Here user_role_field has array values" /> Here user_role_field has array values" /> Here user_role_field has array values"/>

What is the syntax for Stringify in Moustache JS form field

207 views Asked by At
 <input class="autocomplete" paramValue={{param_value}} aria-token-json = "{{{JSON.strigify(user_role_field)}}}">

Here user_role_field has array values, but I want to stringify it. This input field is in Moustache JS.The input field is TokenInput Js package and the aria-token-json accepts Stringify value.

The syntax I applied is not working..Can anyone help please?

1

There are 1 answers

0
Quentin On

Moustache doesn't have a feature that allows you to call arbitrary JS.

You can pass a function in using the Lambda feature

Lambdas

When the value is a callable object, such as a function or lambda, the object will be invoked and passed the block of text. The text passed is the literal block, unrendered. {{tags}} will not have been expanded

  • the lambda should do that on its own. In this way you can implement filters or caching.

Template:

{{#wrapped}}
  {{name}} is awesome.
{{/wrapped}}

Hash:

{
  "name": "Willy",
  "wrapped": function() {
    return function(text, render) {
      return "<b>" + render(text) + "</b>"
    }
  }
}

Output:

<b>Willy is awesome.</b>

but this looks like a situation where you should convert user_role_field to JSON before passing it to Moustache.

(Since JSON isn't HTML, when you include it use {{ and }} and not the triple braces which are for dumping raw HTML source code into the document.)