Internet Technologies:cxp

Page/view syntax Foundation

The page or view syntax is designed to mix imperative and declarative programming.

Xbase++ code sections - the imperative part - start with <% tag and end with %> tag. In addition, arbitrary expressions can easily be embedded into the declarative part of your view using the @(<expression>) inline syntax.

There also is a single-line syntax which marks a line in your view as code. Just use the @ marker as the first character of a line to mark it as a line of code.

The code below shows the previously outlined syntactical elements. The picture further down shows the result produced when requesting the CXP view from within your browser.

<!DOCTYPE html> 
<html> 
<body style="background-color:CornflowerBlue ;color:MintCream"> 
<!-- just HTML markup --> 
<h1>Hello World</h1> 

<!-- inline syntax inside HTML markup--> 
<p>Today is @(Date())!</p> 

<!-- using single-line syntax and inline sytnax instead of a code section --> 
<h1>Again ASCII codes from 39-44</h2> 
<p> 
@FOR n:=39 TO 44 
<!-- since this is markup we need to use HTML comments --> 
CodePoint:@(StrZero(n,2)) <b>IS:</b> @(Chr(n))<br> 
@NEXT n 
</p> 

<h1>ASCII codes from 33-38</h2> 
<!-- code section start/end tag. output rendering via ? --> 
<p> 
<% 
FOR n:=33 TO 38 
 // Normal Xbase++ syntax must be used for code and 
 // comments in the code sections 
 ? "CodePoint:",StrZero(n,2)," <b>IS:</b>",Chr(n),"</br>" 
NEXT n 
%> 
</p> 

</body> 
</html> 

The general idea behind the different syntaxes is to increase readability of your code and markup. The following are considered best-practice rules for coding in CXP:

Use the <% %> tags only for pure Xbase++ code. Do not output HTML inside Xbase++ code sections using ?/??.
Use the @() inline expression syntax in your views to output data, and for binding models to views.
Use the @ single-line marker only for defining the start and end of iterators such as FOR/WHILE, and for conditional sections in your markup enclosed in IF/ELSE/ENDIF
Try to avoid writing business logic mixed with markup. Use code locality tagsinstead for isolating your logic code from view markup.
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.