Clearsilver has a generalized expression syntax which can be used in place of any paramater.
Some example expressions:
Page.Title Page["Title"] Page[varname] Page["Title"] == "Home" (#Page.Count > #1) || (?Page.Next)ClearSilver expressions have four different argument types. They are:
- A number. A number is any string that can be converted to a
number, or you can force a string to be a number using the #
Examples include: 103, 0x1a, -23, +14, #83
- A String. A string is any set of characters within either single quotes or double quotes. There is currently no escaping mechanism.
- A Variable. A variable is either a reference to a local variable (as created by call/def, each, with, loop) or a reference to the global HDF dataset. If your variable name is a number, you must use the $ operator to force variable evaluation.
- Numeric Variable. This is a variable value converted to a number.
ClearSilver expressions have four different evaluation types: variable, string, numeric and boolean. Which evaluation is used depends on the types involved and the operator. Operators are either boolean, numeric, or numeric/string. For numeric/string operators, if either argument is a number, then they are evaluated as a number. Otherwise, the string version of the operator is used. The only really different operator is +, which is numeric addition and string concatenation.
Evaluation as Boolean:
- Number: 0 is false, everything else is true
- String: Empty string is false. String "0" is false. Everything else is true.
- Variable: Non-existing variable is false. Existing variable is treated the same as a string.
- Numeric Variable: Non-existing is 0. Doesn't convert to a number is treated as a 0. Otherwise, converted to a number. Evaluated same as a Number.
- Number: as a number
- String: Converted to a number. If its not a valid number, than it will be converted to 0.
- Variable: If it doesn't exist, its 0. Otherwise, treated the same as a string.
- Numeric Variable: Same as Variable.
- Number: a number in base 10
- String: As String
- Variable: Non-existing variable is the empty string.
- Numeric Variable: Converted to number, than converted to string in base 10.
The list of operators, from low to high precedence:
|,||C Comma Operator||n/a|
|>||String Greater Than||String/Numeric|
|+||String Concat / Add||String/Numeric|
|#||(unary) Force Numeric||Numeric|
|$||(unary) Force Variable||Variable|
|!||(unary) Boolean NOT||Boolean|
|.||Descend Variable Name||Variable|
|[ ]||Expand Variable Name||Variable|
|( )||Function Call||n/a|
Here is an example of rendering data into 2 columns in an HTML table:
<table> <tr> <th>Column 1</th><th>Column 2</th> </tr> <?cs set:count = #0 ?> <?cs each:item = Page.Items ?> <?cs if:count % #2 ?> <tr> <?cs /if ?> <td><?cs var:item.Number ?> - <?cs var:item.Name ?></td> <?cs set:count = count + #1 ?> <?cs if:count % #2 ?> </tr> <?cs /if ?> <?cs /each ?> </table>