- Interpolation
My name is {user.name}
- Conditionals
{{{ if isTrue }}}is true{{{ end }}}
- Iteration
{{{ each people }}}{../name} is {../age} years old.{{{ end }}}
- Helpers
Average: {divide(total, count)}
- Operators
Not Bob? {(name != "Bob")}
A path is a fundamental unit in Benchpress. Any description of where a certain value exists in the data is a path. For instance, in interpolation like Hello, {world}.
, world
is a path to the global world
property.
Benchpress does not have numeric literals, or a special syntax for indexing into an array numerically. Instead, you place the number in the place of the property name. The equivalent of the JS expression x.text[123]
is x.text.123
in benchpress expressions.
{arr.3}
- access element3
of arrayarr
{12}
- access the top-level value stored in the property"12"
{person.pets.0}
- access the person's first pet
Note: Only integers are supported in this manner.
The following special keywords can be used in place of a path:
@true
-boolean
The boolean valuetrue
.@false
-boolean
The boolean valuefalse
.@root
-any
The object passed toparse
. The top-level context object.@value
-any
The value of the current element in an iteration.@key
-string | number
The key of the current element in an iteration.@index
-number
The numerical index of the current element in an iteration. For an object, this differs from the key. For an array, this is normally equal to the key.@first
-boolean
Whether this is the first element in an iteration.@last
-boolean
Whether this is the last element in an iteration.
Paths behave in some unfortunately odd ways in Benchpress in order to maintain maximum backwards-compatibility with templates.js:
../
equals./
at the start of the path. You must use../../
or./../
to go "up one level".abc.def
can either mean thedef
property of theabc
object or thedef
property of each element within theabc
array or object. It behaves the second way if within an iteration block.- There's a lot of magic that is done to make paths backwards-compatible with templates.js behavior, since it worked with incomplete paths. Essentially, the algorithm has to pattern match through the full path, looking for an overlap of the given path within it. The gritty details are in the implementation.