sightly and javascript

Avatar

Avatar

balakumaran_k

Avatar

balakumaran_k

balakumaran_k

15-10-2015

Good morning,

How to generate javascript dynamically using sightly?

Thanks,

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

justin_at_adobe

Employee

Avatar

justin_at_adobe

Employee

justin_at_adobe
Employee

15-10-2015

Correction - I take it back. Sightly can be used to generate JS. It's just a bit ugly because you still need to use HTML tags and you must be sure to use data-sly-unwrap. Sorry for the misinformation. The script name would look like controller.js.html (vs. controller.js.jsp).

Answers (4)

Answers (4)

Avatar

Avatar

justin_at_adobe

Employee

Avatar

justin_at_adobe

Employee

justin_at_adobe
Employee

15-10-2015

@orotas - that's what I meant by "ugly" smiley

Generating JS (or CSS or JSON) with Sightly is possible, but because it uses HTML constructs, it looks weird. Although arguably the same thing could be said about JSP or ESP.

Avatar

Avatar

Paul_McMahon

MVP

Avatar

Paul_McMahon

MVP

Paul_McMahon
MVP

15-10-2015

What would best practice be however? I assume best practice would be use a JSP or Ecma to generate a dynamic JS file. Sightly is defined as being an HTML templating system right, so if you aren't generating HTML shouldn't you be using a different templating language? 

Avatar

Avatar

justin_at_adobe

Employee

Avatar

justin_at_adobe

Employee

justin_at_adobe
Employee

15-10-2015

No. Sightly (at least now) is only able to generate HTML. You could generate JS inside <script> tags in an HTML page, but you can't use Sightly to generate a standalone JS script. The same would be true for JSON, CSS, etc.

Avatar

Avatar

balakumaran_k

Avatar

balakumaran_k

balakumaran_k

15-10-2015

I am just trying to create a angular mobile app using sightly.

In a geomatrix outdoors app example, controller java script is generated via controller.js.jsp using sling. (E.g. geometrixx-outdoors-app/components/angular/ng-image). The java script is dynamically prepared using jcr properties.

How to do this in sightly?

PS: I have gone through the sightly documentation site but couldn't get how to implement this.