HTML Helper

Helper Description
classIf Set the CSS classes if the condition is true.
selectedIf Sets the selected attribute if the condition is true.
checkedIf Sets the checked attribute if the condition is true.
options Generates a select drop-down option list.
stripTags Removes HTML tags from a string, optionally allowing specific tags.

classIf

Set the CSS classes if the condition is true.
Parameters:
  • expression: boolean
    Condition to be checked.
  • clazz: string
    CSS class to set if the condition is true.
          // results in: foo
hbs.compile("{{classIf expression 'foo'}}")({"expression":true});
        

selectedIf

Sets the selected attribute if the condition is true.
Parameters:
  • expression: boolean
    Condition to be checked.
          // results in: selected
hbs.compile("{{selectedIf expression}}")({"expression":true});
        

checkedIf

Sets the checked attribute if the condition is true.
Parameters:
  • expression: boolean
    Condition to be checked.
          // results in: checked
hbs.compile("{{checkedIf expression}}")({"expression":true});
        

options

Generates a select drop-down option list.
Parameters:
  • data: {[key: string]: string}[]
    List of data.
  • options: {value: string, text: string}
    Key names for the selected and displayed values of option in the data element (Optional).
          // results in:
// <option value="1">foo</option>
// <option value="2" selected>bar</option>
hbs.compile("{{{options data selected='2'}}}")({"data":[{"value":1,"text":"foo"},{"value":2,"text":"bar"}]});

// results in:
// <option value="392" selected>JAPAN</option>
// <option value="840">UNITED STATES</option>
hbs.compile("{{{options data selected='392' value='code' text='name'}}}")({"data":[{"code":392,"name":"JAPAN"},{"code":840,"name":"UNITED STATES"}]});
        

stripTags

Removes HTML tags from a string, optionally allowing specific tags.
Parameters:
  • str: string
    The string to remove HTML tags from.
  • allowedTags: string|string[]
    An array of allowed HTML tags. Default is an empty array.
  • replacement: string
    The string to replace HTML tags with. Default is blank.
Return:
  • string The string with HTML tags removed.
          // results in: lorem ipsum dolor sit amet           
hbs.compile("{{{stripTags html}}}")({
  html: '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>',
});

// results in: lorem ipsum <strong>dolor</strong> sit amet
hbs.compile("{{{stripTags html allowedTags}}}")({
  html: '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>',
  allowedTags: ['strong'],
});

// results in: 🍩lorem ipsum 🍩dolor🍩 🍩sit🍩 amet🍩
hbs.compile("{{{stripTags html allowedTags replacement}}}")({
  html: '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>',
  allowedTags: [],
  replacement: '🍩',
});