CU Home
Columbia University Information Technology
SSI Flow Control

Web Design > SSI Flow Control

The basic flow control elements are:

<!--#if expr="test_condition" -->
<!--#elif expr="test_condition" -->
<!--#else-->
<!--#endif-->

The if element works like an if statement in a programming language. The test condition is evaluated and if the result is true, then the text until the next elif, else. or endif element is included in the output stream The elif or else statements are be used to put text into the output stream if the original test_condition was false. These elements are optional. The endif element ends the if element and is required.

test_condition Is One of the Following:
string
true if string is not empty
string1 = string2
string1 != string2
Compare string1 with string 2. If string2 has the form /string/ than it is compared as a regular expression. Regular expressions have the same syntax as those found in the Unix egrep command.
( test_condition )
true if test_condition is true
! test_condition
true if test_condition is false
test_condition1 && test_condition2
true if both test_condition1 and test_condition2 are true
test_condition1 || test_condition2
true if either test_condition1 or test_condition2 is true
"=" and "!=" bind more tightly than "&&" and "||"; "!" binds most tightly. Thus, the following are equivalent:

<!--#if expr="$a = test1 && $b = test2" -->
<!--#if expr="($a = test1) && ($b = test2)" -->

Anything that's not recognized as a variable or an operator is treated as a string. Strings can also be quoted: 'string'. Unquoted strings can't contain whitespace (blanks and tabs) because it is used to separate tokens such as variables. If multiple strings are found in a row, they are concatenated using blanks. So,

string1 string2 results in string1 string2
'string1 string2' results in string1 string2

Variable substitution is done within quoted strings. You can put a dollar sign into the string using backslash quoting:

<!--#if expr="$a = \$test" -->

Example

The below example will print "in foo" if the DOCUMENT_URI is /foo/file.html, "in bar" if it is /bar/file.html and "in neither" otherwise:

<!--#if expr="\"$DOCUMENT_URI\" = \"/foo/file.html\"" -->

in foo

<!--#elif expr="\"$DOCUMENT_URI\" = \"/bar/file.html\"" -->

in bar

<!--#else-->

in neither

<!--#endif-->


« Back to SSI Quick Reference Go to Interactivity and Design »