data-sly-test (Sightly)

Avatar

Avatar

nikunjk71293848

Avatar

nikunjk71293848

nikunjk71293848

15-10-2015

Hi,

 

Can we test global variables declared in javascript inside HTML with the help of data-sly-test command?

 

I have set a var xtest = false inside javascript and have used following statement inside HTML: <div data-sly-test.abcvar = "${xtest}">hello</div>.

But hello text is displayed in all scenario. How do i test a global variable inside HTML with the help of sightly?

 

Thanks,

Nikunj

View Entire Topic

Avatar

Avatar

gabriel_walt

Employee

Avatar

gabriel_walt

Employee

gabriel_walt
Employee

15-10-2015

Hi Prateek,

As explained, this only works for server-side JavaScript, so I'm assuming that this is the case for you.

This is how a simple example would like like:

<div data-sly-use.logic="logic.js"> <p data-sly-test="${logic.foo}">${logic.foo}</p> </div>

Assuming that you have something like following corresponding JavaScript:

use(function () { return { foo: 'My foo text...' }; });

What it does: if the foo text exists and is not empty, then the <p> element will be displayed, showing the content of the foo text.

In case this doesn't answer your question, then please explain further what exactly you try to achieve.

Best,
Gabriel