Highlighted

Not able to consum js use API in sightly

Avatar

Avatar

lovepreetk75597

Avatar

lovepreetk75597

lovepreetk75597

08-05-2019

Hi,

I ma trying to consume js use API in sightly but it is not working. Following are my js and htl files:-

abc.js:-

'use strict';

use(function () {

    alert("inside");

    var message = "Hello World";

    return {

       

        hello: message

    };

});

abc.html:-

<div data-sly-use.logic="abc.js">

    ${logic.hello}

</div>

Ideally it should print "Hello world". Also that alert is not coming.

Am i missing out something?

Thanks in advance.

Regards,

Lovepreet

Replies

Highlighted

Avatar

Avatar

berliant

Employee

Avatar

berliant

Employee

berliant
Employee

08-05-2019

Within your sample, you need to make sure that you placed your js next to abc.html.

Here is an example for We.Retail:

1748806_pastedImage_0.png

1748873_pastedImage_1.png

The code sample is from HTL and the JavaScript Use-API

Highlighted

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Answer

2.3K
smacdonald2008

08-05-2019