Expand my Community achievements bar.

SOLVED

Confusion about JSP and HTML pages

Avatar

Level 7

Hi,

I find myself confused every now and then regarding HTML pages, JSP pages, etc. in CQ5. I guess I have to re-read the Sling docs again.

But basically, at the moment, under our app folder (e.g. /apps/foo) we have a bunch of .html pages that are requested by our Angular JS app via AJAX.

I want to add some dynamic code to these pages (e.g. JSP scriptlets, etc.)

What is the proper way of doing this in CQ 5?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 8

The proper way is generate the HTML files your angular app uses from a JSP. 

So what you would is create the following:

  • A template at say /apps/foo/templates/angular - this template points a resource type of /apps/foo/components/angular
  • You create a components at /apps/foo/components/angular and then a JSP are /apps/foo/components/angular/angular.jsp.
  • In angular.jsp you put you static HTML content along with whatever scriptlets you want. 
  • Then you create a CQ page at say /content/angular/en/myapp based on you template at /apps/foo/templates/angular
  • You point your angular app at /content/angular/en/myapp.html 

View solution in original post

3 Replies

Avatar

Correct answer by
Level 8

The proper way is generate the HTML files your angular app uses from a JSP. 

So what you would is create the following:

  • A template at say /apps/foo/templates/angular - this template points a resource type of /apps/foo/components/angular
  • You create a components at /apps/foo/components/angular and then a JSP are /apps/foo/components/angular/angular.jsp.
  • In angular.jsp you put you static HTML content along with whatever scriptlets you want. 
  • Then you create a CQ page at say /content/angular/en/myapp based on you template at /apps/foo/templates/angular
  • You point your angular app at /content/angular/en/myapp.html 

Avatar

Former Community Member

Oratas has covered the basics.... Or you could think about moving to v6 so you can use HTML with Sightly and finally get rid of all that JSP nonsense.

Avatar

Employee

I'd advise you to go with Sightly instead of JSP for any new project as it is designed to replace JSP. This will give you automatic proper HTML encoding and cross-site scripting protection built-in. It will also force some healthy separation of concerns, preventing the kind of code & markup mix you typically can end-up with in JSPs. Thus making the markup overall more readable.