Helper | Description |
---|---|
slice | Extract a portion of a string. |
nltobr | Replace \n with <br> tags. |
sprintf |
Returns a string produced according to the formatting string format. It uses sprintf-js internally. Check https://github.com/alexei/sprintf.js for more information. |
lowercase | Changes the string to lowercase. |
uppercase | Changes the string to uppercase. |
concat | Concat two or more strings. |
join | Join the elements of an array with the specified separator. |
split | Split a string into an array by the specified characters. |
val: string
start: number
end: number
// results in: Just
hbs.compile("{{slice str 0 4}}")({"str":"Just Wow"});
// results in: Wow
hbs.compile("{{slice str 5}}")({"str":"Just Wow"});
// results in: Wow
hbs.compile("{{slice str -4}}")({"str":"Just Wow"});
val: string
// results in: It's<br>just<br>now
hbs.compile("{{{nltobr str}}}")({"str":"It's\njust\nnow"});
format: string
args: ...any
// Argument swapping:
// results in: Hello Dolly!
hbs.compile("{{sprintf '%s %s!' str1 str2}}")({"str1":"Hello","str2":"Dolly"});
// results in: foo bar 55 baz 20
hbs.compile("{{sprintf '%s %s %d %s %d' 'foo' 'bar' 55 'baz' '20'}}")();
// Named arguments:
// results in: Hello Dolly
hbs.compile("{{sprintf 'Hello %(name)s' user}}")({"user":{"name":"Dolly"}});
// results in: Hello Dolly
hbs.compile("{{sprintf 'Hello %(name)s' name=str}}")({"str":"Dolly"});
val: string
// results in: just wow
hbs.compile("{{lowercase str}}")({"str":"JUST WOW"});
val: string
// results in: JUST WOW
hbs.compile("{{uppercase str}}")({"str":"just wow"});
args: ...string
// results in: Hello world!
hbs.compile("{{concat 'Hello' ' world' '!'}}")();
collection: string[]
separator: string
// results in: Hands & legs & feet
hbs.compile("{{{join collection ' & '}}}")({"collection":["Hands","legs","feet"]});
val: string
separator: string
// results in: ['a', 'b', 'c']
hbs.compile("{{split list}}")({"list":"a,b,c"});
// results in: <ul>
// <li>a</li>
// <li>b</li>
// <li>c</li>
// </ul>
hbs.compile(`<ul>
{{#each (split list ',')}}
<li>{{this}}</li>
{{/each}}
</ul>`)({"list":"a,b,c"});