Command <%...%> code section Foundation

Defines a code section

Syntax
<% ... %> or
<%
 ...
%>
Description

A <CXP/> file normally contains HTML tags, just like an HTML file. However, a <CXP/> file can also contain code sections surrounded by the tags <% and %>. These code sections are executed on the server and can be made up of any expression, statement, procedure, or class valid in the Xbase++ language.

Inside a code section, the ? command is used to write to the current output section. The following example writes the string "Hello World" into the body element of the document.

<html> 
<body> 
<% 
? "Hello World!" 
%> 
</body> 
</html> 

The command ? internally uses the method ::HttpResponse:WriteStr(), which performs HTML-encoding and appends a CRLF-pair to the string. Data without a line break can be output using the command ??, which uses the ::HttpResponse:Write() method instead. To output the data as-is, without any encoding or line breaks, the method ::HttpResponse:WriteRaw() must be called directly.

Examples
<%...%>
<html> 
<head> 
<!-- Output the version data inside the title --> 
<!-- without a crlf pair                      --> 
<title>Greetings from <%??Version()%></title> 
<body> 
<% 

// This iteration repeats the output, adding 16 lines 
// of text to the resulting page 
FOR n := 1 TO 16 
  ? "<p style='background-color:#f5"+StrZero(n*6,2)+"20'>Hello world v2!</p>" 
NEXT n 
%> 
</body> 
</html> 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.