Toggle menu

Swag Handlebars Helpers

The following helpers are available both client and server-side in the various fields that use the Handlebars templates, and in email and PDF generation.

These helpers are based upon the Swag Handlebars Helpers released under the MIT license and available here www.npmjs.com/package/swag Their documentation has been updated and reproduced below.

For anyone not familiar with the examples, they are characters from Futurama (opens new window)

Use in Forms

These helpers can be used in all of the form field types that include the Handlebars editor.

Data may be supplied to your template by the field's default function, updated using the manipulation function, or, in the case of the Ajax Template, be requested from an End Point or other API Server worker available browser-side.

JSON Data

JSON data is often supplied in a result object or array, so you'll often use result in your template.

For example, if your data is supplied as:

{
    "jsonrpc": "2.0",
    "id": 42,
    "result": {
        "result": [{
            "name": "Leela",
            "deliveries": 8021
        }, {
            "name": "Bender",
            "deliveries": 239
        }, {
            "name": "Fry",
            "deliveries": 1
        }]
    }
}

You could use the HTML "ul" helper, and Inflections "inflect" helper, to create a template like:

{{#ul result class="deliveries-list"}}
    {{name}} - {{inflect deliveries "delivery" "deliveries" true}}
{{/ul}}

Which would output:

  • Leela - 8021 deliveries
  • Bender - 239 deliveries
  • Fry - 1 delivery

Collections

Manipulate items in arrays and objects. Includes "first", "last", "after", "before", "join", "sort", "length", "empty", "any", "inArray", "eachIndex" and "eachProperty".

Comparisons

Conditionally render blocks if the comparison is met. Includes "is", "isn't", "greater than", "less than", "or" and "and".

Dates

Date manipulation. Includes "formatDate", "now" and "timeago".

HTML

Generates HTML elements. Includes "ul", "ol" and "br".

Inflections

Change the form of words. Includes "inflect" and "ordinalize".

Logging

Generate logging. Includes "log" and "debug".

Maths

Perform calculations. Includes "add", "subtract", "multiply", "divide", "floor", "ceil" and "round".

Miscellaneous

Miscellaneous functions. Includes "default".

Numbers

Work with numbers. Includes "toFixed", "toPrecision", "toExponential", "toInt", "toFloat" and "digitGrouping".

Strings

Manipulate strings. Includes "lowercase", "uppercase", "capitalizeFirst", "titleize", "sentence", "reverse", "truncate", "center", "newLineToBr" and "sanitize".

Share this page

Facebook icon Twitter icon email icon

Print

print icon