I was looking over the expression options used in sightly. I tried the below line of code, but it seems just render the text over the page, can someone provide use of options with some good examples.
${'Assets' @ i18n, locale='fr-CH', hint='Translation Hint'}
${'Page {0} of {1}' @ format = [count,total] }
I have tried and understand the below code to include the parsys
<div data-sly-resource ="${@path='question_list', resourceType='wcm/foundation/components/parsys'}"></div>
Also from where i can get the whole list of data-sly-[elements].
Thanks
Options in Sightly expressions can have two different kind of usage:
Note: to easily try out the examples provided below, you can install the REPL tool on your AEM instance.
On a plain expression (that is not located in a
data-sly-*
statement), following options are possible:Example:
${'Page {0} of {1}' @ format = [1, 10]}
Displays:
Page 1 of 10
locale
allows to change the language if something different to the current page language is to be taken, andhint
allows to provide help to the translator and to distinguish strings that might be identical but that have different meanings.Example:
${'Number' @ i18n, locale = 'de', hint = 'Media DPS Folio Number'}
Displays:
Nummer
Example:
${['foo', 'bar'] @ join = '-'}
Displays:
foo-bar
Example:
${'<p>Hi!</p><script>alert("hack!")</script>' @ context = 'html'}
Displays:
<p>Hi!</p>
Following statements allow the expression options as listed above, because these statements are similar to writing the expression without statement:
This example:
<p data-sly-text="${currentPage.title}">Lorem ipsum</p>
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>
This example:
<p href="#" data-sly-attribute.href="${currentPage.path}"></p>
Is equivalent to:
<p href="${currentPage.path}"></p>
(This can be useful for writing valid HTML as the W3C HTML5 validator verifies that URLs are correctly constructed. Also it allows to leave 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 data-sly-attribute can also be used to set multiple attributes by providing an iterable key-value object, like in the example below. But this usage of data-sly-attribute doesn't allow to use any options:
<div data-sly-attribute="${properties}"></div>
Following statements accept any expression options as they allow to pass named parameters:
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>
Example:
<template data-sly-template.tmpl="${@ foo}">${foo} world</template>
<p data-sly-call="${tmpl @ foo = 'hello'}"></p>
Displays:
<p>hello world</p>
Following statements allow a custom list of options:
Notice that:
<div data-sly-include="${ @ path = 'path/to/template.html'}"></div>
Is equivalent to:
<div data-sly-include="${'path/to/template.html'}"></div>
Or even to:
<div data-sly-include="path/to/template.html"></div>
(I'd always opt for the shorter writing form.)
Options for data-sly-include (other than
path
) are:Here too the short writing form is:
<div data-sly-resource="par"></div>
Same as for
data-sly-include
, but it additionally accepts following options:And following statements allow no expression options: