config/view.js
file.
Name Config | Description |
---|---|
views_dir: string |
The directory path where the view will be placed. The default is the views directory directly under the application root. |
partials_dir: string |
The directory path where the reusable templates are located. The default is the views/partials directory directly under the application root.Reusable templates are automatically loaded when you launch the Express Sweet application and can be called from other templates. |
layouts_dir: string |
The directory path where the reusable base template is located. The default is the views/layout directory directly under the application root. |
default_layout: string |
The path to the layout file used by default. The default is the views/layout/default.* File directly under the application root.The extension of the default layout file is replaced with the extension specified by extension .
|
extension: string |
Extension for templates and partials files. The default is .hbs . |
beforeRender: (req: express.Request, res: express.Response) => Promise<void>|void |
Hook function just before the view is rendered. For example, you can set your own local variables that can be used within the view.
|
{{{body}}}
{{{block "script"}}}
{{#contentFor "script"}}
CONTENT HERE
{{/contentFor}}
{{!< LAYOUT}}
If path starts with '.'
LAYOUT is relative to template
Else If `layoutsDir` is set
LAYOUT is relative to `layoutsDir`
Else
LAYOUT from path.resolve(dirname(template), LAYOUT)
res.render('veggies', {
title: 'My favorite veggies',
veggies: veggies,
layout: 'layout/veggie'
});
res.render('veggies', {
title: 'My favorite veggies',
veggies: veggies,
layout: null // render without using a layout template
});
If path starts with '.'
layout is relative to template
Else If `layoutsDir` is set
layout is relative to `layoutsDir`
Else
layout from path.resolve(viewsDir, layout)
Function | Description |
---|---|
eq() |
Determine whether or not two values are equal (===).
Parameters:
Return:
|
eqw() |
Determine whether or not two values are equal (==) i.e. weak checking.
Parameters:
Return:
|
neq() |
Determine whether or not two values are not equal (!==).
Parameters:
Return:
|
neqw() |
Determine whether or not two values are not equal (!=) weak checking.
Parameters:
Return:
|
lt() |
Check for less than condition (a < b).
Parameters:
Return:
|
lte() |
Check for less than or equals condition (a <= b).
Parameters:
Return:
|
gt() |
Check for greater than condition (a > b).
Parameters:
Return:
|
gte() |
Check for greater than or equals condition (a >= b).
Parameters:
Return:
|
not() |
Logical NOT of any expression.
Parameters:
Return:
|
ifx() |
Helper to imitate the ternary '?:' conditional operator.
Parameters:
Return:
|
empty() |
Check if it is empty. If the value is an array, returns true if there are no elements. If the value is a string, the leading and trailing spaces are trimmed and then checked. Parameters:
Return:
|
notEmpty() |
Check that it is not empty. If the value is an array, returns true if there is an element. If the value is a string, the leading and trailing spaces are trimmed and then checked. Parameters:
Return:
|
count() |
Determine the length of an array.
Parameters:
Return:
|
and() |
Returns the boolean AND of two or more parameters passed i.e it is true iff all the parameters are true.
Parameters:
Return:
|
or() |
Returns the boolean OR of two or more parameters passed i.e it is true if any of the parameters is true.
Parameters:
Return:
|
coalesce() |
Returns the first non-falsy value from the parameter list. Works quite similar to the SQL's COALESCE() function, but unlike this checks for the first non-false parameter.
Parameters:
Return:
|
includes() |
Returns boolean if the array contains the element strictly or non-strictly.
Parameters:
Return:
|
regexMatch() |
Returns true if the given str matches the given regex.
Parameters:
Return:
|
Function | Description |
---|---|
cacheBusting() |
Returns the Assets path containing the file update time parameter.
Parameters:
Return:
|
Function | Description |
---|---|
jsonStringify() |
Stringify an object using JSON.stringify.
Parameters:
Return:
|
jsonParse() |
Parses the given string using JSON.parse.
Parameters:
Return:
|
Function | Description |
---|---|
replace() |
Returns a new string with some or all matches of a pattern replaced by a replacement.
Parameters:
Return:
|
split() |
Split `string` by the given `character`.
Parameters:
Return:
|
formatBytes() |
Convert bytes to just the right units(KB, MB, GB, TB, PB, EB, ZB, YB).
Parameters:
Return:
|
Function | Description |
---|---|
formatDate() |
Use moment to format the date.
Parameters:
Return:
|
Function | Description |
---|---|
number2locale() |
Returns the language-sensitive representation of a number as a string.
Parameters:
Return:
|
Function | Description |
---|---|
add() |
Calculates the sum of two numbers.
Parameters:
Return:
|
sub() |
Calculates the difference of the given values.
Parameters:
Return:
|
multiply() |
Calculate the multiplication of the given values.
Parameters:
Return:
|
divide() |
Compute the division of the given values.
Parameters:
Return:
|
ceil() |
Round up the value.
Parameters:
Return:
|
floor() |
Rounds down a number.
Parameters:
Return:
|
abs() |
Returns an absolute value.
Parameters:
Return:
|