JSON builds helper

Given the following context:

{
  dogs: [ {name: "rex"}, {name: "tobi"} ]
}

How can I dump dogs as an array, i.e. something likeJSON.stringify(dogs)

I tried with {#dogs}{@contextDump}{/dogs}, but (logically) it outputs:

 {"name": "rex"}{"name": "tobi"}

but not:

["name": "rex"}, {"name": "tobi"}]

thanks

+4
source share
1 answer

This is possible using filters . Your template will look like this:

{dogs|js|s}

js- this is basically JSON.stringify and sunescape are all that will cancel quotes in JSON.

See jsFiddle .

+9
source

All Articles