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:
// 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:
// 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"}]});
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: '🍩',
});