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

Send argument in Javascript Use API from HTML

Avatar

Avatar
Applaud 25
Level 2
Shaheena_Sheikh
Level 2

Likes

2 likes

Total Posts

96 posts

Correct Reply

1 solution
Top badges earned
Applaud 25
Applaud 5
Affirm 1
Validate 10
Validate 1
View profile

Avatar
Applaud 25
Level 2
Shaheena_Sheikh
Level 2

Likes

2 likes

Total Posts

96 posts

Correct Reply

1 solution
Top badges earned
Applaud 25
Applaud 5
Affirm 1
Validate 10
Validate 1
View profile
Shaheena_Sheikh
Level 2

01-06-2021

I have a js file with the following code:

"use strict";
use(function () {

//var url= this.url; //line 3
var url = "http://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/use-api-javascript.html?lang..."; //line 4
var getRequest = new org.apache.commons.httpclient.methods.GetMethod(url),
client = new org.apache.commons.httpclient.HttpClient(),
status = new org.apache.commons.httpclient.HttpStatus();
var info = {};
var statusCode= client.executeMethod(getRequest);
if (statusCode != 404)
info.code = true;
else
info.code = false;
return info;
});

HTML:

<template data-sly-use.item="java model path">

<sly data-sly-use.status="'myfile.js' @url='${item.url}'">

</template>

 

The above code works fine for the hard coded value of URL in JS line 4. Now if i uncomment line 3 and comment out line 4 from my JS. The code breaks.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 5
Level 2
mayur_satav
Level 2

Likes

6 likes

Total Posts

8 posts

Correct Reply

2 solutions
Top badges earned
Boost 5
Applaud 5
Boost 3
Affirm 1
Boost 1
View profile

Avatar
Boost 5
Level 2
mayur_satav
Level 2

Likes

6 likes

Total Posts

8 posts

Correct Reply

2 solutions
Top badges earned
Boost 5
Applaud 5
Boost 3
Affirm 1
Boost 1
View profile
mayur_satav
Level 2

01-06-2021

Hi @Shaheena_Sheikh ,

I checked the above code and I think it is because of the synchronous request in

 

http.open('HEAD', url, false);

 

If this value is false, the send() method does not return until the response is received and this might be the case parsys stops loading. If possible could you please share more details so that I can debug it?

 

Edited

To sent URL as a parameter, you should use data

 

 

<div data-sly-use.status='myfile.js' @ url=${file2.path}" data-example="${status.aFunction}" />

 

 

you can access arguments by using 'this.'

 

 

use(function () {
var url = this.url;
.
.
.
});

 

 

 

2nd method

access data variable attribute through class

 

<div class="myClass" data-sly-use.status="myfile.js" data-url="${file2.path}"> in HTML
var args= $(".myClass");
var url= args.data("url");

 

Thank you.

Answers (0)