Skip to main content

Object Operators

When we need to work with objects, these operators will help with your markdown.

List of Operators

{{ assign }}

Assign a value to a variable.

Params

* `name` **{string}**: Name of variable.
* `value` **{string|boolean|object|array}**: Stored value of variable. Value can be one of these types: string, boolean, object, array. Value is accessible directly by the assigned name, eg. `{{ email }}`.

The {{assign}} operator allows us to assign values for reuse in other expressions.

To use variables assigned via {{assign}}, they will be available under the defined name. For example, for the the assignment: {{assign "email" "myemail@example.com"}}, the value can be referenced by {{email}}.

If a variable is re-assigned a different value, the new value will be accessible under the same variable name.

To assign a string to a value:

{{assign "email" "myemail@example.com"}}

# Show value
{{email}}

To simplify more, results of other operators can be evaluated into a variable.

{{assign "mathExpression" (multiply 2 2)}}

# Results
{{mathExpression}}

Illegal names

Certain names are preserved for global variables and will cause a compilation error. Please avoid the following names:

  • {{deal}}
  • {{current}}
  • {{hubspot}}
  • {{opportunity}}

{{ extend }}

Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.

Params

* `objects` **{Object}**: One or more objects to extend.
* `returns` **{Object}**

{{ filterBy }}

Params

* `objects` **{Object}**:
* `property` **{String}**: The property picked.
* `operator` **{}**: The operator to use. Operators must be enclosed in quotes: `">"`, `">="`, `"!="`, `"="`, `"<="`, and `"<"`.
* `value` **{String}**: The value to check for.
* `returns` **{Object}**

Example

To return an object of all annual SKUs, we would write the following operator:

{{filterBy (values deal.skus) "unitPricingSchedule" "=" "year"}}

To calculate the total cost of all one-time SKUs on the order form, we would write the following operator:

{{sum
(pluck
(filterBy (values deal.skus) "unitPricingSchedule" "=" "one-time")
"netPrice"
)
}}

{{ forIn }}

Block helper that iterates over the properties of an object, exposing each key and value on the context.

Params

* `context` **{Object}**
* `options` **{Object}**
* `returns` **{String}**

{{ forOwn }}

Block helper that iterates over the own properties of an object, exposing each key and value on the context.

Params

* `object` **{Object}**: The object to iterate over.
* `options` **{Object}**
* `returns` **{String}**

{{ get }}

Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.

Params

* `prop` **{String}**: The property to get, optionally using dot notation for nested properties.
* `context` **{Object}**: The context object
* `options` **{Object}**: The handlebars options object, if used as a block helper.
* `returns` **{String}**

{{ getObject }}

Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.

Params

* `prop` **{String}**: The property to get, optionally using dot notation for nested properties.
* `context` **{Object}**: The context object
* `returns` **{String}**

{{ hasOwn }}

Return true if key is an own, enumerable property of the given context object.

Params

* `key` **{String}**
* `context` **{Object}**: The context object.
* `returns` **{Boolean}**

Example

{{hasOwn context key}}

{{ isObject }}

Return true if value is an object.

Params

* `value` **{String}**
* `returns` **{Boolean}**

Example

{{isObject "foo"}}
//=> false

{{ JSONparse }}

Parses the given string using JSON.parse.

Params

* `string` **{String}**: The string to parse

Example

<!-- string: '{"foo": "bar"}' -->
{{JSONparse string}}
<!-- results in: { foo: 'bar' } -->

{{ merge }}

Deeply merge the properties of the given objects with the context object.

Params

* `object` **{Object}**: The target object. Pass an empty object to shallow clone.
* `objects` **{Object}**
* `returns` **{Object}**

{{ pick }}

Pick properties from the context object.

Params

* `properties` **{Array|String}**: One or more properties to pick.
* `context` **{Object}**
* `options` **{Object}**: Handlebars options object.
* `returns` **{Object}**: Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.

{{ stringify }}

Stringify an object using JSON.stringify.

Params

* `object` **{Object}**: Object to stringify
* `returns` **{String}**

Example

<!-- object: { foo: 'bar' } -->
{{stringify object}}
<!-- results in: '{"foo": "bar"}' -->

{{ toPath }}

Take arguments and, if they are string or number, convert them to a dot-delineated object property path.

Params

* `prop` **{String|Number}**: The property segments to assemble (can be multiple).
* `returns` **{String}**

{{ values }}

Returns an array of the given object's own enumerable string-keyed property values.

Params

* `returns` **{Object}**: Returns an object with the picked values.