|
|
|
Writing a template expression
Template expressions are statements you use to compute or evaluate
a value. You can define expressions in Code view or in the Optional
Region dialog box.
There are two ways to define expressions in code: using the
<!-- TemplateExpr: expr = “your expresson”-->
comment, or @@your expression@@. You insert the expression in
the template. When you apply the template, Dreamweaver evaluates
the expression and displays the value in the template-based
document.
You can use an expression to store a value and display it in
a document. For example, an expression can be as simple as the
value of a parameter, such as @@ParamA@@, or complex enough
to compute values which alternate the background color in a
table row, such as @@(_index&1) ? red : blue @@ .
You can also define expressions for if and multiple-if conditions.
When an expression is used in a conditional statement, it is
evaluated as true or false. If the condition is true, the optional
region will show; if it is false it won’t.
You can write basic template expressions using the Insert Optional
Region command; for information about inserting optional regions,
see Inserting an optional region. You can define more complex
conditions, such as a multiple-if condition or a computed text
condition, directly in Code view. To see a multiple-if code
example, see Creating a Multiple If condition.
When you write a template expression in the code, an expression
marker appears in Design view. To edit the expression in Design
view, select the marker and in the Property inspector modify
your entry.
The template expression language is a small subset of JavaScript,
and uses JavaScript syntax and precedence rules. You can use
JavaScript operators to write an expression like this:
@@firstName+lastName@@
The following features and operators are supported:
- numeric literals, string literals (double-quote syntax only),
boolean literals (true or false)
- variable reference (see Expression Object Model for the
defined variables)
field reference (the "dot" operator)
- unary operators: +, -, ~, !
- binary operators: +, -, *, /, %, &, |, ^, &&,
||, <, <=, >, >=, ==, !=, <<, >>
- conditional operator: ?:
parentheses: ()
The following types are used: boolean, IEEE 64-bit floating
point, string, and object. The only objects available are those
defined by the About the Expression Object Model.
Dreamweaver templates do not support the use of JavaScript
"null" or "undefined" types. Nor do they
allow scalar types to be implicitly converted into an object;
thus, the expression "abc".length would trigger an
error, instead of yielding the value 3.
|