Parameters in Mature expressions can have two different types of use:
- They can act as instructions processing the output of an expression, as a function.
- When an expression is in the data-sly- * statement, they allow you to provide instructions or parameters to this statement.
Note. To easily try the examples below, you can install the REPL tool on your AEM instance.
In a simple expression (which is not in the data-sly-* ), the following options are possible:
- format :. String concatenation.
Example: ${'Page {0} of {1}' @ format = [1, 10]}
Displays: Page 1 of 10 - i18n : Translate lines. In addition,
locale allows you to change the language if you need to do something different from the current language of the page, and hint allows you to provide help to the translator and distinguish between strings that can be identical, but have different meanings.
Example: ${'Number' @ i18n, locale = 'de', hint = 'Media DPS Folio Number'}
Displays: Nummer - join : Defines a string separator to display between array elements.
Example: ${['foo', 'bar'] @ join = '-'}
Displays: foo-bar - context : Control how HTML escaping and XSS protection are performed.
Example: ${'<p>Hi!</p><script>alert("hack!")</script>' @ context = 'html'}
Displays: <p>Hi!</p>
The following statements allow you to use the expression parameters listed above, because these operators are similar to writing an expression without an operator:
- data-sly-text :
This example: <p data-sly-text="${currentPage.title}">Lorem ipsum</p>
This is equivalent to: <p>${currentPage.title}</p>
(This can be useful if you want to leave placeholders provided by the HTML designer in the markup.)
So this example: <p data-sly-text="${'Page {0} of {1}' @ format = [1, 10]}"></p>
Displays: <p>Page 1 of 10</p> - data-sly attribute :
This example: <p href="#" data-sly-attribute.href="${currentPage.path}"></p>
Equivalent to: <p href="${currentPage.path}"></p>
(This can be useful for writing valid HTML, as the W3C HTML5 validator validates the URLs and also leaves placeholders provided by the HTML designer in the markup.)
So this example: <p data-sly-attribute.title="${['foo', 'bar'] @ join = '-'}"></p>
Displays: <p title="foo-bar"></p>
Note that the sly attribute attribute can also be used to set multiple attributes by providing an iterable key object, as in the example below. But this use of the sly-data attribute does not allow the use of any options: <div data-sly-attribute="${properties}"></div>
The following statements accept any parameters of an expression because they allow you to pass named parameters:
- data usage :
Example: <p data-sly-use.bar="${'logic.js' @ foo = 'hello'}">${bar}</p>
logic.js: use(function () { return this.foo + " world"; });
Displays: <p>hello world</p> - tricky data pattern and data crawl :
Example:
<template data-sly-template.tmpl="${@ foo}">${foo} world</template>
<p data-sly-call="${tmpl @ foo = 'hello'}"></p>
Displays: <p>hello world</p>
The following operators allow you to configure a list of parameters:
- data-sly-include :
Please note: <div data-sly-include="${ @ path = 'path/to/template.html'}"></div>
This is equivalent to: <div data-sly-include="${'path/to/template.html'}"></div>
Or even: <div data-sly-include="path/to/template.html"></div>
(I always choose a shorter form of writing.)
Parameters for data-crafty (except path ):- prependPath: Adds something to the path.
- appendPath: Adds something after the path.
- wcmmode: Changes the WCM mode for the included file.
- data-sly-resource :
Here is also a short form of writing: <div data-sly-resource="par"></div>
Same as for data-sly-include , but additionally accepts the following parameters:- selectors . To replace the selector.
- addSelectors: Adding selectors.
- removeSelectors: Remove selectors.
- resourceType:. To determine or change the type of resource (required only if it has not yet been determined by the contents of the node).
- decorationTagName and cssClassName:. For backward compatibility with how AEM added DIV elements around included components in the JSP.
And the following statements do not allow the use of expression parameters:
source share