The XSSI extensions to SRE-http

SRE-http supports a subset of the Apache XSSI extensions to the NCSA HTTPD server side includes:
<!-- #set var="varname" value="some value" -->
#set is used to define variables for use in other HTTPD-style server side includes. For example:
<!--#set var="category" value="help" -->

<!--#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 used if the original test_condition is false. These elements are optional. Note that the first true statement is used, and else is always true (it does NOT take an expr).

The endif element ends the if element and is required.

test_condition can be any valid REXX statement. In addition, the following Apache (C) style comparions are also supported:

string
true if string is not empty
string1 = string2
Compare string1 with string 2.
string1 != string2
Compare string1 with string 2, TRUE if not equal.
( 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

"=" binds more tightly than "&&" and "||". "!" binds most tightly. Thus, the following are equivalent:

    <!--#if expr="$a = test1 && $b = test2" -->
    <!--#if expr="($a = test1) && ($b = test2)" -->
Would you like to see a demo of #IF

Using #set variables

#set variables are used as textual substitutions within quoted. This substituion is performed where they may reasonably occur as an argument to an SSI directive. This includes the config, exec, flastmod, fsize, include, and set directives, as well as the arguments to conditional operators.

Notes:

  • In order to insert a literal dollar sign into an NCSA-style SSI directive, you must use the backslash (\) character as a quote:
        <!--#if expr="$a = \$test" -->
    
  • If a variable reference needs to be substituted in the middle of a character sequence that might otherwise be considered a valid identifier in its own right, it can be disambiguated by enclosing the reference in braces. For example:
        <!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}" -->
    

    This will result in the Zed variable being set to "X_Y" if REMOTE_HOST is "X" and REQUEST_METHOD is "Y".

  • When using a #set variable in an #ECHO element, you should not include the $ preface. For example, assuming you've defined <!-- #set var="foo" value="hello world" -->, then:
  • Correct: <!-- #echo var="foo" -->
  • InCorrect: <!-- #echo var="$foo" -->
  • You can reference regular CGI variables using the $ syntax (as noted in the following example).
  • If you define a #set variable that uses a CGI variable name (say, PATH_TRANSLATED), then this #set value will be used.
  • Technical note: SRE-http stores #set variables in the GLOBAL. stem, using a tail name of !varname (that is, preface the varname with a !). You can reference, or define, these variables in INTERPRET SRE-http style SSIs.
    For example, , the following are equivalent:
    <!-- #set var="monster" value="ghost" -->
    <!-- interpret code globals.!MONSTER="ghost" -->
  • 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 -->
    
    Need more information on the Apache XSSI syntax?