Flow Control

Using the variables set with the set directive and the various environment and include variables, a limited flow control syntax can be used to generate a certain amount of dynamic content on server-parsed pages.

The syntax of the if/else functions is as follows:

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

expr can be a string, which is considered true if nonempty, or a variety of comparisons between two strings. Available comparison operators are =, !=, <, <=, >, and >=. If the second string has the format /string/, the strings are compared with regular expressions. Multiple comparisons can be strung together with && (and) and || (or). Any text appearing between the if/elif/else directives are displayed on the resulting page. An example of such a flow structure follows:

<!—#set var="agent" value="$HTTP_USER_AGENT" —>

<!—#if expr="$agent = /Mozilla/" —>


Something else!

This code displays Mozilla! if you're using a browser that passes Mozilla as part of its user_agent string, and it displays Something else! otherwise.



Was this article helpful?

0 0

Post a comment