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

Sightly is a server-side template language, so you cannot use it to do client-side operations. The confusion might come from the fact that it is using data attributes, or from the fact that it can also use JavaScript as scripting language to prepare the variables. But despite it looking a bit like a client-side thing, it is actually all evaluated on the server: a Sightly template has to be placed into AEM components, just like the JSP templates. Sightly is basically a replacement for JSP.

If you wish to do a client-side script to control the display of an element, then I'd first give it an ID (e.g. <div id="myid">), and do some jQuery script to show/hide it, like following:

jQuery(function($) { $('div#myid').toggle(xtest); });

Best,
Gabriel