#if, #elif, #else and #endif commands

SSI pages can also contain flow control commands. These provide the ability to perform advanced alteration of a the html page.

The various flow control commands are as follows:

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

When one of the expressions matches, then the html enclosed in the matching block is parsed and returned to the client. Flow control commands can be nested.

Expression Meaning
string False if string is non-empty, true otherwise
string1 = string2 True if the strings match
string1 != string2 True if the strings do not match
string1 > string2 True if the string1 is greater than string2(string compare)
string1 >= string2 True if the string1 is greater than or equal to string2(string compare)
string1 < string2 True if the string1 is less then string2(string compare)
string1 <= string2 True if the string1 is less than or equal to string2(string compare)
! expression Inverts the result of an expression; true if expression is false
( expression ) Groups an expression together; true if the expression is true
expression1 || expression2 True if either expression1 or expression2 is true
expression1 && expression2 True if both expression1 and expression2 are true
  1. Inside strings, variables starting with a '$' are expanded. For example "$SERVER_PROTOCOL" will be expanded to HTTP/1.1
  2. For the '=' and '!=' comparisons, string2 will be interpreted as a regular expression if it starts and ends with a '/'.
  3. Strings can be quoted using single quotes. If they arn't quoted, any white space between adjacent strings are merged into a single space.
  4. Operators bind in the following order (tightest first): !, =, !=, ||, &&

Caching of expressions

In order to improve performance of expressions and regular expressions, Zeus Web Server caches the last 100 expressions it parsed, and the last 100 regular expressions. These values can be altered using the following tunables:

tuning!ssi!expressioncachesize 100
tuning!ssi!regexcachesize      100

Apache Compatibility

The Zeus implementation follows as closly as possible the documentation for Apache, however Apache has some bugs in its expression parsing (especially '$' expansion). By default Zeus parses the expressions without implementing the bugs. In order to switch the parser to the 'Apache bug Compatibility' mode, set the following tunable (in web/global.cfg):

tuning!ssi!apachebugcompat yes

Example

An example use of flow control commands would be to report back to the client the browser that is being used.

<!--#if expr=" ! $HTTP_USER_AGENT " -->
No user agent specified
<!--#elif expr=" $HTTP_USER_AGENT = /MSIE/ " -->
Microsoft Internet Explorer
<!--#elif expr=" $HTTP_USER_AGENT = /Mozilla/ " -->
Mozilla or something that identifies itself as such (almost everything)
<!--#else -->
Other browser type
<!--#endif -->
Content Manager [Administrator] 16 December 2005  Permalink  
Download Free Trial

Recent Articles

Other Resources



www.zeus.com