Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Not able to consum js use API in sightly

Avatar

Avatar
Validate 1
Level 2
lovepreetk75597
Level 2

Likes

3 likes

Total Posts

24 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 3
View profile

Avatar
Validate 1
Level 2
lovepreetk75597
Level 2

Likes

3 likes

Total Posts

24 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 1
Give Back 3
View profile
lovepreetk75597
Level 2

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

Avatar

Avatar
Give Back 50
Employee
berliant
Employee

Likes

207 likes

Total Posts

315 posts

Correct Reply

98 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
berliant
Employee

Likes

207 likes

Total Posts

315 posts

Correct Reply

98 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
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

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

08-05-2019