Article
· Jan 22, 2021 2m read

Embedded JavaScript trick – Markers allow use of < and >

This concept may be known to some, but I just found it very useful and I would like to share as it may help someone else.

If you are working with CSP or Zen you sometimes come across the need to use embedded JavaScript. Suppose you are working with some loops, which use < or > as shown in example below:

&js< 

               var test = document.getElementById('seTest');

               for (var i = 0; i < test.options.length; i++) {

                              // Do Something here with my test.options[i]...

               }             

>

Now, because we are using < inside this for loop Studio will give a lot of errors and fail to compile.

The solution is simple. We have a marker feature (see https://docs.intersystems.com/latest/csp/docbook/Doc.View.cls?KEY=GCOS_embedded#GCOS_embedded_html_marker) which we can use whenever we come across the use of < or > inside our embedded JavaScript – for example:

&js@< 

               var test = document.getElementById('seTest');

               for (var i = 0; i < test.options.length; i++) {

                              // Do Something here with my test.options[i]...

               }             

>@

This compiles and works as it should.

Discussion (2)2
Log in or sign up to continue