Hi Vlad,

thanks for your answer again.

The "4" is indeed a literal. But I'm thinking about an other way of handling that.

Best,

Sandro

Am 23.10.15 um 08:59 schrieb Vlad Bailescu:
Hi Sandro,

Sightly blocks/expressions are only aware of the HTML context, not the
whole DOM tree so you cannot use the attributes like this.

However, I assume data-component-id="4" is generally not hardcoded, but
rather coming from some sort of expression, like
data-component-id="${some_expression}". In this case you can pass the same
expression to the Use-Object initialization: @id=${some_expression}

Vlad

On Thu, Oct 22, 2015 at 9:43 PM, Sandro Boehme <[email protected]> wrote:

Hello,

for the Sling Sitebuilder I would like to pass an id that is specified as
an element attribute to the Sightly server side JavaScript file defined by
the JS Use-API. Is that possible?

This example works:

<sly class="component" data-component-type="bs-p" data-component-id="4"
data-sly-use.componentResource="${'component.js' @id='4'}">
     ...
</sly>

component.js:
"use strict";
use(function () {
     return resource.getChild(this.id);
});

content:
{
         "jcr:primaryType":"sling:Folder",
         "4":{
                 "jcr:primaryType":"nt:unstructured",
                 "value":"foo bar"
         }
}


But in the 'use' block of the 'sly' tag I specify the '4' as literal
(@id='4'). Instead I would like to reference it e.g. like
@id=attributes.data-component-id. Is that possible?

Thanks in advance for any help!

Best,

Sandro



Reply via email to