Skip to main content

Embedded Code

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",!
  &html<
    <html>
      <body>
        <b>I'm bold!</b>
        <i>I'm italic</i>
        <u>I'm underlined</u>
      </body>
    </html>
  >
  WRITE "end"
  • The &html directive must be indented; it cannot appear in column 1.

  • The &html directive is not case-sensitive; you can specify &HTML, &Html, or &html.

  • The &html directive can appear on the same line as a label, a command, or a /* ... */ comment. Like all ObjectScript code, it must be separated from an argumentless command that precedes it by at least two spaces.

  • The &html directive is followed by an open angle bracket, with no intervening spaces, line breaks, or comments. The embedded HTML code is terminated by a close angle bracket.

  • HTML code within Embedded HTML and the close angle bracket do not have to be indented. They can appear in column 1, though for clarity of code the use of indents is recommended.

  • HTML code does not have to include the <html> structural tag (or any other structural tag); however, structural tags are fully supported.

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",!
  &html<
        <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",!
  &html7<
        <b>I'm bold!</b>
        <i>I'm italic</i>
        <u>I'm underlined</u>
      >7
  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.

FeedbackOpens in a new tab