Functions and types for BajoTemplate.buildCompileImports
With these functions now your templates can use all listed functions below. The imports are automatically injected into the template's scope during compilation.
- Source
// In your template file (e.g., template.html)
<p><%= _t('Hello, %s!', user.name) %></p>
<p><%= _format(user.birthDate, 'date') %></p>
<p><%= _routePath('home:/user/{id}/profile', { id: user.id }) %></p>Methods
(inner) FnDump(value)
Dump a value to console.
| Name | Type | Description |
|---|---|---|
value | * | Value to be dumped. |
- Source
(inner) FnExcerpt(text, maxWordsopt, trailCharsopt) → {string}
Get excerpt of a string.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | String to be excerpted. | ||
maxWords | number | <optional> | 50 | Max number of words. |
trailChars | string | <optional> | '...' | Characters to append if truncated. |
- Source
Excerpted string.
- Type:
- string
(inner) FnFindRoute(name, methodopt) → {object|null}
Find route by name. Only available when Waibu plugin is installed & loaded.
See Waibu.findRoute for more details.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Route name. | ||
method | string | <optional> | 'GET' | HTTP method (e.g., 'GET', 'POST'). |
- Source
Route object or null if not found.
- Type:
- object |
null
(inner) FnFormat(val, type, optsopt) → {string}
Format text with optional parameters.
See Bajo.format for more details.
| Name | Type | Attributes | Description |
|---|---|---|---|
val | * | Value to be formatted. | |
type | string | Value type (e.g., 'string', 'number', 'date'). | |
opts | object | <optional> | Optional formatting options. |
- Source
Formatted text.
- Type:
- string
(inner) FnGetSetting(key) → {*}
Get a setting value by key. Only available when Waibu plugin is installed & loaded.
See Waibu.getSetting for more details.
| Name | Type | Description |
|---|---|---|
key | string | Setting key. |
- Source
Setting value.
- Type:
- *
(inner) FnHasPlugin(nameOrAlias) → {boolean}
Check if a plugin is loaded by its name or alias.
| Name | Type | Description |
|---|---|---|
nameOrAlias | string | Plugin name or alias. |
- Source
True if the plugin is loaded, false otherwise.
- Type:
- boolean
(inner) FnJsonStringify(value, replaceropt, spaceopt) → {string}
JSON stringify a value. Only available when WaibuMpa plugin is installed & loaded.
See WaibuMpa.jsonStringify for more details.
| Name | Type | Attributes | Description |
|---|---|---|---|
value | * | Value to be stringified. | |
replacer | object | <optional> | Optional replacer function or array. |
space | string | | <optional> | Optional space for indentation. |
- Source
JSON stringified value.
- Type:
- string
(inner) FnParseMarkdown(value) → {string}
Parse markdown text. Only available when BajoMarkdown plugin is installed & loaded. See BajoMarkdown.parse for more details.
| Name | Type | Description |
|---|---|---|
value | string | Markdown text to be parsed. |
- Source
Parsed HTML string.
- Type:
- string
(inner) FnRoutePath(name, optionsopt) → {string|null}
Get route path by name. Only available when Waibu plugin is installed & loaded.
See Waibu.routePath for more details.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Route name. | ||
options | object | <optional> | {} | Options object. |
- Source
Route path or null if not found.
- Type:
- string |
null
(inner) FnTitleize(str) → {string}
Get titleized version of a string.
| Name | Type | Description |
|---|---|---|
str | string | String to be titleized. |
- Source
Titleized string.
- Type:
- string
(inner) FnTranslate(text, …args) → {string}
Translate text with optional parameters.
| Name | Type | Attributes | Description |
|---|---|---|---|
text | string | Text to be translated. | |
args | * | <repeatable> | Optional parameters for translation. |
- Source
Translated text.
- Type:
- string