The App.template module handles Handlebars templates. If precompiled templates is used add them to the App.templates.compiled
namespace, and they will automatically be picked up by the getTemplate()
function.
Example
// Example of how fetch a template
App.template.getTemplate('/my/template');
// It is also possible to fetch an template from an provided url
App.template.getTemplate('/my/template', '/url/to/my/template.handlebars');
Members
(static) App.templates
Methods
(static) compileTemplate(name, urlopt) → {Promise}
compileTemplate returns a compiled handlebars template.
It will first try to fetch the template from the list of precompiled templates.
If the template is not found, it will fetch the template the server and compile it. Subsequent requests for the same template name will be returned from the list of compiled templates.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | of the handlebars template |
|
url |
String |
<optional> |
Url from where to fetch the template from, defaults to |
Returns:
Promise that will resolve to the compiled Handlebar template
- Type
- Promise
(static) getTemplate(name, urlopt) → {function}
getTemplate returns a compiled handlebars template.
It will first try to fetch the template from the list of precompiled templates.
If the template is not found, it will fetch the template the server and compile it. Subsequent requests for the same template name will be returned from the list of compiled templates.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | of the handlebars template |
|
url |
String |
<optional> |
Url from where to fetch the template from, defaults to |
Returns:
Compiled Handlebar template
- Type
- function
(static) initHandlebars()
(static) isPartialRegistered(name) → {Boolean}
Checks if a partial is registred or not
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of the partial to check for existence |
Returns:
boolean Boolean whether the partial is registred or not
- Type
- Boolean
(static) setupHelper(name, fn)
Registers an Handlebars helper function
Parameters:
Name | Type | Description |
---|---|---|
name |
String | of the helper |
fn |
String | the JavaScript function |
(static) setupPartial(name, src)
Registers an Handlebars partial
Example
// Will register a partial with the name 'topbar-components'
App.templates.setupPartial('topbar-components', 'helium/templates/topbar/partials/components');
// The partial can later be called from a template using the following syntax \{{> topbar-components}}
Parameters:
Name | Type | Description |
---|---|---|
name |
String | of the partial |
src |
String | the lookup name for the partial |
(static) shouldShorten(text, truncateOptions:) → {boolean}
Check whether truncate the string or not.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | : content which is truncated |
truncateOptions: |
object | Information about the truncation. |
truncateOptions.textLength: |
number | After what character length it should be truncated. |
truncateOptions.leftTextLength: |
number | After what character length it should be truncated from left. |
truncateOptions.rightTextLength: |
number | After what character length it should be truncated from right. |
Returns:
- Type
- boolean
(static) truncateText(text, truncateOptions:) → {string}
Truncate the string.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | : content which is truncated |
truncateOptions: |
object | Information about the truncation. |
truncateOptions.textLength: |
number | After what character length it should be truncated. |
truncateOptions.leftTextLength: |
number | After what character length it should be truncated from left. |
truncateOptions.rightTextLength: |
number | After what character length it should be truncated from right. |
truncateOptions.truncateDirection: |
string | Truncate direction either left, right or centre. |
Returns:
- Type
- string