The expression service parses Litespeed.js template syntax.
The main use for this service is to bind service value into views and view components like 'data-ls-echo' and 'data-ls-if' rely on it heavily.
The expression parser detects service path references, evaluate them and parses the final results.
Litespeed.js expression also supports 'mustache' or 'twig' like filters to give a lot more flexibility and power.
Parses a Litespeed.js expression.
Param | Type | Description |
---|---|---|
string | string | Expression string. Use {{object.path}} to evaluate a service path or add a pipe to apply a filter {{object.path |
def | string | Default value to use when expression has evaluated with empty result (optional) |
Resulted expression string or def parameter value if empty result.
conatiner.set('user', {
'name': 'john doe',
'email': 'john@example.com'
}, true, true);
filter.add('uppercase', function (value) {
return value.toUpperCase();
});
let name = expression.parse('hello {{user.name|uppercase}}'); // hello JOHN DOE
let empty = expression.parse('your age is {{user.age|uppercase}}', 30); // your age is 30