Expand my Community achievements bar.

SOLVED

sightly and javascript

Avatar

Level 2

Good morning,

How to generate javascript dynamically using sightly?

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Employee

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).

View solution in original post

5 Replies

Avatar

Level 2

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.

Avatar

Employee

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

Correct answer by
Employee

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).

Avatar

Level 8

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

Employee

@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.