Include CSP in CLS.
Is there any way to include a CSP page within a CLS?
Example: #Include file.csp
Context: I work with a legacy that most screens are built using only CLS. I'm trying to change this by separating the frontend layers to be built only with CSP and backend layers using CLS. I improvised a method that injects an iframe to render the CSP in CLS through that iframe, but I'm still not happy. I need to know if there is any way to include this CSP using some specific resource for this.
Comments
a CSP page will actually compile into a .cls, so you can call specific methods of your CSP page by calling the method using ##class(mycsppackage.mycsppage).methodname() (the csp package name is configurable but defaults to 'csp')
Sorry, but I think it wasn't clear. I want to call CSP to render in CLS. In other words, I want to include the CSP method, but the entire CSP.
look at the generated class from the csp. you should be able to call the OnBody() method to create the text stream containing the html
Actually, you should read this doc: https://docs.intersystems.com/iris20241/csp/docbook/Doc.View.cls?KEY=GC…
there are other callbacks you will need to call besides OnBody(). Make sure to call them in succession to get full page functionality.
Do you understand that when I say CSP, I'm not referring to the %CSP.Page, but rather the .csp file?
the .csp file compiles into a subclass of type %CSP.Page. When it is called, on the back end the various methods of the subclass of %CSP.Page are involved in order to stream the content of the .csp page. Please see the documentation link above for more details.
Thank you very much for the clarification! Do you know where these CLS compiled through CSP are?
It's been a while since I had to look these up. You probably have to select the option for 'show generated code' order to find it. Unless you overwrote the default package, they should show up as csp.****.cls classes (in the "csp" package)
I found! But now to call the page within CLS, just “write csp.package.page”?
just like you would call any class - "write ##class(csp.package.page).method()"
The big question is this, I don't want to call a method, I want to render the entire CSP, an entire page.
if you are wanting to completely render the page within the context of another page, then using <iframe src="package.page.csp" </iframe> is going to be your best bet. Remember that a csp page isn't just a static HTML snippet - it is an entire renderable page, along with pre-page headers, etc. That is why OnPreHttp(), OnBody() and OnPostHttp() are all included in the page framework for a .csp. If you simply want to show what is 'rendered' when you call the page directly, you can play with calling OnPage() (which contains the compiled version of the entire body of your .csp file), but that may not operate correctly when called in isolation - it is intended to be called as part of a full pageload process, which the iframe approach above would provide.
From a class that extends %CSP.Page you can include a CSP page using the Include() method inherited from %CSP.Page, like:
Do ..Include("TestInclude.csp")
This is what is actually generated when a csp page containing a CSP INCLUDE tag documented here is compiled, like:
<CSP:INCLUDE page="TestInlude.csp">
Please note this is legacy (deprecated?).
Thank you very much for the explanation. And what would be the correct way to work on this separation between front-end and backend? An API written in Caché (cls backend) where there can be a front-end (nodeJS)?
I don't understand your question in the context of the original question:
"I work with a legacy that most screens are built using only CLS"
If you want to rewrite using modern approach, then use your favorite front-end framework and implement a REST API in the Caché backend.......and maybe move from legacy Caché/Ensemble to modern IRIS as well...