Object

Overview

obj

Create an object from a string.

The string will be parsed as JSON, and the resulting object will be returned.

If the string is not valid JSON, it will be executed as JavaScript code, and the resulting object will be returned.

If both fail, the error will be returned.

Usage

Syntax:

{{obj [string] }}

Example:

{{! Partial: Message }}
<p>{{msg}} {{name}}</p>
{{> Message (obj '{"msg":"Hello","name":"Mom"}') }}
{{> Message (obj '{"msg":"Hello","name":"Jim"}') }}
{{> Message (obj 'return {msg:"Goodbye",name:"Gargamel"}') }}

Output:

<p>Hello Mom</p>
<p>Hello Jim</p>
<p>Goodbye Gargamel</p>