13.5 Conditional Statements Apache allows you to include only select portions of a server document using conditional statements. These conditional statements are based on the value of server-side variables initialized earlier using the SSI set command. The Apache flow-control statements allow you to effectively customize a document without adding more complex CGI programs to perform the same task. There are four Apache flow-control statements: <!--#if expr=" expression " --> <!--#elif expr=" expression "--> <!--#else--> <!--#endif--> Each works as you would expect from an ordinary scripting language. Note that each if must have a closing endif server-side statement. For example: <!--#if expr="$myvar=activated" --> <B>The variable appears to be activated</B> <!--#elif expr="$myvar=inactive"--> <B>The variable appears to be inactive</B> <!--#else--> <B>The variable has an unknown value</B> <!--#endif--> Table 13-2 shows the allowed expressions, where the order of operations is as expected in a traditional programming language. Note that in some cases, var2 is allowed to be an egrep-based regular expression if it is surrounded by slashes (/) on both sides. Table 13-2. XSSI conditional expressions
Finally, you can place regular strings inside single quotes to preserve any whitespaces. If a string is not quoted, extra whitespaces are ignored. For example: this is too much space This string does not have quotes and will be collapsed to: this is too much space However, if you place the string in single quotes, the whitespace is preserved: /'this is too much space/' You can also place strings in double quotes, but you will have to escape each one while inside the expr="" expression, as shown here: <!--#if expr="\" $HTTP_REFERER\" != " --> |
Team-Fly |
Top |