Article
Alex Kogan · 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.

12
5 419
Discussion (2)2
Log in or sign up to continue

really helpful trick!  thanks for sharing @Alex Kogan , I didn't previously know this was an option :)

As an addition, when you run into the code, which has a simple comment, and inside the comment there is > or < - that code would most likely not even compile and this same trick would work there as well.