Directive #code directive Foundation

Controls where code is emitted by the CxcBuilder

Syntax
<%#code locality=<locality-name>%>
Description

The #code directive is used to specify the locality of the code section following the directive. The supported locality tokens are described in the table below. The default locality is "page-render". The CxcBuilder automatically switches back to that locality after it has emitted the code section immediately following a #code directive.

Locality Tokens
Token Description
page-init Code section is injected at the end of the :Init() method of the page class
page-load Code section is injected into the :Load() method of the page class. :Load() is executed when the page binary is loaded into the worker process.
page-unload Code section is injected into the :Unload() method of the page class. :Unload() is executed when the page binary is unloaded from worker process. This usually occurs before the worker process gets recycled. The exact time is not determined.
page-render*) Code section is injected into the :Render() method of the page class. :Render() is where the HTML output (view content) is created.
page-global Code section is injected into the module header of the page class implementation file. Use this locality for defining your own functions, classes or static declarations. #include statements should also be placed in this locality.
  1. Default locality

page-load/page-unload is a good place for database connections such as DacSession() connect / disconnect or table USE operations, as this will increase performance if a worker process is used to handle multiple requests.

Examples
Declare static variable
<%#code locality="page-global"%> 
<% 
// This section is injected into the module header 
STATIC aData := { 3, 5, 7, 11 } 

FUNCTION MyHelper(cInput) 
RETURN(cOutput) 
%> 
<!-- this comment and the following code goes into --> 
<!-- the page-render method.                       --> 
<h1> 
<% 
? Version() 
%> 
</h1> 
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.