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

How to pass dialog property value to AJAX request in sightly JAVA Script use API.?

Avatar

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
Kkkrish
Level 4

Likes

27 likes

Total Posts

107 posts

Correct Reply

1 solution
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
Kkkrish
Level 4

27-11-2017

Am using server-side JavaScript USE API to read the dialog properties like below

use(function () {

var myproperty = properties.get("renderpagetype");

return { callajaxvariable: myproperty,

};

});

How to pass/get this dialog property value to AJAX request in sightly.?

(i.e. i need the dialog value which has been retrieved by JS USE API into a page level Java script function call/usage)

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

183 likes

Total Posts

233 posts

Correct Reply

70 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

183 likes

Total Posts

233 posts

Correct Reply

70 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile
Ravi_Pampana
MVP

27-11-2017

You can use variable value coming from JS Use api to pass to the script in sightly like below

// Update the js filename as required

<div data-sly-use.component="useapi.js">

//Variable defined in USE API

    <h1>${component.title}</h1>

// scriptString is required to read the value as javascript string in sightly

    <script>

        var titleVar = '${component.title @ context="scriptString"}';

       // Pass the value to the ajax function

   </script>

</div>

Other approach is, you can do it directly in Sightly if the dialog value is not modified in USE API like below

<script>

        var titleVar = '${properties.title @ context="scriptString"}';

       // Pass the value to the ajax function

</script>

Hope this helps...

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
Level 10
edubey
Level 10

Likes

273 likes

Total Posts

1,502 posts

Correct Reply

392 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
Level 10
edubey
Level 10

Likes

273 likes

Total Posts

1,502 posts

Correct Reply

392 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
edubey
Level 10

27-11-2017

Since js use API executes on the server and your javascript ajax will executes on the browser.

You would need a way to pass these values to the front end so that javascript can read it.

I would not encourage using script tags inside HTML, it blocks the page parsing. You either use custom data attributes or hidden input fields to store these values in HTML

Also, I am not sure why you are using JS Use API to get dialog fields. Use API is slower as compare to java sling model or expression in sightly as it executes twice (JS Rhino -> Java -> Compile). See if you can avoid it.