javaaemsightly

How to set the variable value to the resource selectors?


I need to set the selector using data-sly-resource. It works if I set the selector name directly. But I need to pass the selector name which is saved in variable. How to set the value of "selector" variable ("settings1" or "settings2") to the selectors of data-sly-resource?

<template data-sly-template.edit="${ @ settings }">
        <div data-sly-test.selector="${settings == 'data' ? 'settings1' : 'settings2'}">
            <div data-sly-resource="${ @path='home', resourceType='/aem/test/components/component', selectors='${selector}' }"></div>
        </div>
</template>

This code doesn't work...


Solution

  • You can pass HTL variables directly to the expression options:

    data-sly-resource="${ @path='home', resourceType='/aem/test/components/component', selectors=selector }"

    BTW, instead of data-sly-test you could use data-sly-set to assign the value for selector.