A collection of Handlebars template helpers which can be used within HTML templates.

Methods

  • For checkboxes, if the value of the checkbox is true, add the "checked" property, otherwise add nothing.

    Parameters

    • value: any

    Returns string

    Example

    <label>My Checkbox</label>
    <input type="checkbox" name="myCheckbox" {{checked myCheckbox}}>
  • For use in form inputs. If the supplied value is truthy, add the "disabled" property, otherwise add nothing.

    Parameters

    • value: any

    Returns string

    Example

    <button type="submit" {{disabled myValue}}>Submit</button>
    
  • Concatenate a number of string terms into a single string. This is useful for passing arguments with variable names.

    Parameters

    • Rest ...values: string[]

      The values to concatenate

    Returns SafeString

    Example: Concatenate several string parts to create a dynamic variable

    {{filePicker target=(concat "faces." i ".img") type="image"}}
    
  • Construct an editor element for rich text editing with TinyMCE or ProseMirror.

    Parameters

    • content: string

      The content to display and edit.

    • Optional options: {
          target: string;
          button: boolean;
          class: string;
          editable: boolean;
          engine: string;
          collaborate: boolean;
      }
      • target: string

        The named target data element

      • button: boolean

        Include a button used to activate the editor later?

      • class: string

        A specific CSS class to add to the editor container

      • editable: boolean

        Is the text editor area currently editable?

      • engine: string

        The editor engine to use, see TextEditor.create.

      • collaborate: boolean

        Whether to turn on collaborative editing features for ProseMirror.

    Returns SafeString

    Example

    {{editor world.description target="description" button=false engine="prosemirror" collaborate=false}}
    
  • A ternary expression that allows inserting A or B depending on the value of C.

    Parameters

    • criteria: boolean

      The test criteria

    • ifTrue: string

      The string to output if true

    • ifFalse: string

      The string to output if false

    Returns string

    The ternary result

    Example: Ternary if-then template usage

    {{ifThen true "It is true" "It is false"}}
    
  • Translate a provided string key by using the loaded dictionary of localization strings.

    Parameters

    • value: any
    • options: any

    Returns string

    Example: Translate a provided localization string, optionally including formatting parameters

    <label>{{localize "ACTOR.Create"}}</label> <!-- "Create Actor" -->
    <label>{{localize "CHAT.InvalidCommand" command=foo}}</label> <!-- "foo is not a valid chat message command." -->
  • A string formatting helper to display a number with a certain fixed number of decimals and an explicit sign.

    Parameters

    • value: string | number

      A numeric value to format

    • options: {
          decimals: number;
          sign: boolean;
      }

      Additional options which customize the resulting format

      • decimals: number

        The number of decimal places to include in the resulting string

      • sign: boolean

        Whether to include an explicit "+" sign for positive numbers *

    Returns SafeString

    The formatted string to be included in a template

    Example

    {{formatNumber 5.5}} <!-- 5.5 -->
    {{formatNumber 5.5 decimals=2}} <!-- 5.50 -->
    {{formatNumber 5.5 decimals=2 sign=true}} <!-- +5.50 -->
    {{formatNumber null decimals=2 sign=false}} <!-- NaN -->
    {{formatNumber undefined decimals=0 sign=true}} <!-- NaN -->
  • Render a form input field of type number with value appropriately rounded to step size.

    Parameters

    • value: number
    • options: any

    Returns SafeString

    Example

    {{numberInput value name="numberField" step=1 min=0 max=10}}
    
  • A helper to create a set of radio checkbox input elements in a named set. The provided keys are the possible radio values while the provided values are human readable labels.

    Parameters

    • name: string

      The radio checkbox field name

    • choices: object

      A mapping of radio checkbox values to human readable labels

    • options: {
          checked: string;
          localize: boolean;
      }

      Options which customize the radio boxes creation

      • checked: string

        Which key is currently checked?

      • localize: boolean

        Pass each label through string localization?

    Returns SafeString

    Example: The provided input data

    let groupName = "importantChoice";
    let choices = {a: "Choice A", b: "Choice B"};
    let chosen = "a";

    Example: The template HTML structure

    <div class="form-group">
    <label>Radio Group Label</label>
    <div class="form-fields">
    {{radioBoxes groupName choices checked=chosen localize=true}}
    </div>
    </div>
  • Render a pair of inputs for selecting a value in a range.

    Parameters

    • options: {
          name: string;
          value: number;
          min: number;
          max: number;
          step: number;
      }

      Helper options

      • name: string

        The name of the field to create

      • value: number

        The current range value

      • min: number

        The minimum allowed value

      • max: number

        The maximum allowed value

      • step: number

        The allowed step size

    Returns SafeString

    Example

    {{rangePicker name="foo" value=bar min=0 max=10 step=1}}
    
  • A helper to create a set of <option> elements in a <select> block based on a provided dictionary. The provided keys are the option values while the provided values are human-readable labels. This helper supports both single-select and multi-select input fields.

    Parameters

    • choices: object | object[]

      A mapping of radio checkbox values to human-readable labels

    • options: any

      Options which configure how select options are generated by the helper

    Returns SafeString

    Generated HTML safe for rendering into a Handlebars template

    Example: The provided input data

    let choices = {a: "Choice A", b: "Choice B"};
    let value = "a";

    The template HTML structure

    <select name="importantChoice">
    {{selectOptions choices selected=value localize=true}}
    </select>

    The resulting HTML

    <select name="importantChoice">
    <option value="a" selected>Choice A</option>
    <option value="b">Choice B</option>
    </select>

    Example: Using inverted choices

    let choices = {"Choice A": "a", "Choice B": "b"};
    let value = "a";

    The template HTML structure

    <select name="importantChoice">
    {{selectOptions choices selected=value inverted=true}}
    </select>

    Example: Using nameAttr and labelAttr with objects

    let choices = {foo: {key: "a", label: "Choice A"}, bar: {key: "b", label: "Choice B"}};
    let value = "b";

    The template HTML structure

    <select name="importantChoice">
    {{selectOptions choices selected=value nameAttr="key" labelAttr="label"}}
    </select>

    Example: Using nameAttr and labelAttr with arrays

    let choices = [{key: "a", label: "Choice A"}, {key: "b", label: "Choice B"}];
    let value = "b";

    The template HTML structure

    <select name="importantChoice">
    {{selectOptions choices selected=value nameAttr="key" labelAttr="label"}}
    </select>
  • Convert a DataField instance into an HTML input fragment.

    Parameters

    • field: DataField

      The DataField instance to convert to an input

    • options: object

      Helper options

    Returns SafeString

  • Convert a DataField instance into an HTML input fragment.

    Parameters

    • field: DataField

      The DataField instance to convert to an input

    • options: object

      Helper options

    Returns SafeString