Using Caché ObjectScript
Embedded Code
[Home] [Back] [Next]
InterSystems: The power behind what matters   

ObjectScript supports the embedding within it of the following types of code:

Embedded HTML
Embedded HTML statements are set off from the rest of the code by the &html< code > directive, as shown in the following example:
  WRITE "start",!
        <b>I'm bold!</b>
        <i>I'm italic</i>
        <u>I'm underlined</u>
  WRITE "end"
The body of an &html directive should contain valid HTML tags. You can format your HTML in any way you like with indents and white space. Blank lines within HTML code are retained. Studio recognizes the &html directive and uses the colorizer to syntax color the HTML tags.
The Macro Preprocessor expands macros before the ObjectScript parser handles any Embedded HTML code. There is no support for macro processing within embedded HTML. For example, you cannot use ##; single-line comments within Embedded HTML. You can, however, use the results of the macro preprocessor in Embedded HTML code, as shown in the following example:
#Define NumFunc ##Expression(17+4)
  WRITE "start",!
        <b>I'm bold!</b>
        <i>I'm italic $$$NumFunc</i>
        <u>I'm underlined</u>
  WRITE "end"
&html Marker Syntax
You can identify a specific &html directive using user-defined marker syntax. This syntax consists of a character or string specified between “&html” and the open angle bracket character. The reverse of this marker must appear immediately after the closing angle bracket at the end of the Embedded HTML. The following example uses 7 as a marker character:
  WRITE "start",!
        <b>I'm bold!</b>
        <i>I'm italic</i>
        <u>I'm underlined</u>
  WRITE "end"
Note that no white space (space, tab, or line return) is permitted between &html, the marker, and the open angle bracket, and no white space is permitted between the closing angle bracket and reverse-marker.
A marker can be a single character or a series of characters. A marker cannot contain the following punctuation characters:
<({ + - / \ | * })>
A marker cannot contain a whitespace character (space, tab, or line return). It may contain all other printable characters and combinations of characters, including Unicode characters. The marker and reverse-marker are case-sensitive.
The corresponding reverse-marker must contain the same characters as marker in the reverse order. For example: &htmlABC< ... >CBA. If marker contains a [ or ( character, reverse-marker must contain the corresponding ] or ) character. The following are examples of valid &html marker and reverse-marker pairs:
  &html@@< <b>Be bold!</b> >@@
  &html[< <b>Be bold!</b> >]
  &htmlMyTest< <b>Be bold!</b> >tseTyM
  &htmlA16[a< <b>Be bold!</b> >a]61A
When selecting a marker character or string, note the following important restriction: the HTML code cannot contain the character sequence “>reversemarker” anywhere in the code, including in literal strings and comments. For example, if the marker is “ABC”, the character string “>CBA” cannot appear anywhere in the Embedded HTML.
For further details on using Embedded HTML, refer to Developing Zen Applications.
Embedded JavaScript
Embedded JavaScript allows you to include JavaScript code within an ObjectScript program. You can use any of the following syntax forms of the Embedded JavaScript directive:
&js< JavaScript code >
&jscript< JavaScript code >
&javascript< JavaScript code >
The syntax and parsing of the Embedded JavaScript directive, including the use of marker syntax, are the same as for Embedded HTML. Refer to Embedded HTML for details.
For further details on using Embedded JavaScript, refer to Developing Zen Applications.
Embedded SQL
Embedded SQL allows you to include SQL code within an ObjectScript program. The syntax is &sql( ). For example:
  &sql( SELECT Name INTO :n FROM Sample.Person )
  WRITE "name is: ",n
For further details, refer to the Using Embedded SQL chapter in Using Caché SQL.

Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA