docs.roxen.comView this page in a printer friendly mode
DocsRoxenWebServer 4.5Web Developer ManualIf Tags
Copyright  2012, Roxen Internet Software
Suggestions, comments & compliments

<if accept>
<if client>
<if clientvar>
<if config>
<if cookie>
<if date>
<if defined>
<if domain>
<if exists>
<if expr>
<if false>
<if group>
<if internal-exists>
<if ip>
<if kerberos-auth>
<if language>
<if match>
<if Match>
<if module>
<if pragma>
<if prestate>
<if referrer>
<if sizeof>
<if supports>
<if time>
<if true>
<if type-from-data>
<if type-from-filename>
<if user>
<if variable>
<if Variable>


Provided by module: Tags: RXML 2 tags

The <if> tag is used to conditionally include its contents. <else> or <elseif> can be used afterwards to include alternative content if the test is false.

The tag itself is useless without its plugins. Its main functionality is to provide a framework for the plugins. It is mandatory to add a plugin as one attribute. The other attributes provided are and, or and not, used for combining different plugins with logical operations.

Note: Since XML mandates that tag attributes must be unique, it's not possible to use the same plugin more than once with a logical operator. E.g. this will not work:

<if variable='var.x' and='' variable='var.y'>
   This does not work.

You have to use more than one tag in such cases. The example above can be rewritten like this to work:

<if variable='var.x'>
   <if variable='var.y'>
     This works.

The If plugins are sorted according to their function into five categories: Eval, Match, State, Utils and SiteBuilder.

Eval plugins

The Eval category is the one corresponding to the regular tests made in programming languages, and perhaps the most used. They evaluate expressions containing variables, entities, strings etc and are a sort of multi-use plugins.

<if variable=' > 0' and='' match=' is No'>

<if variable=' > 0' not=''>
  &; is less than 0
  &; is greater than 0

The tests are made up either of a single operand or two operands separated by an operator surrounded by single spaces. The value of the single or left hand operand is determined by the If plugin.

If there is only a single operand then the test is successful if it has a value different from the integer 0. I.e. all string values, including the empty string "" and the string "0", make the test succeed.

If there is an operator then the right hand is treated as a literal value (with some exceptions described below). Valid operators are "=", "==", "is", "!=", "<", ">", "<=", and ">=".

<set variable='var.x' value='6'/>
<if variable='var.x > 5'>More than one hand</if>
More than one hand

The three operators "=", "==" and "is" all test for equality. They can furthermore do pattern matching with the right operand. If it doesn't match the left one directly then it's interpreted as a glob pattern with "*" and "?". If it still doesn't match then it's splitted on "," and each part is tried as a glob pattern to see if any one matches.

In a glob pattern, "*" means match zero or more arbitrary characters, and "?" means match exactly one arbitrary character. Thus "t*f??" will match "trainfoo" as well as "tfoo" but not "trainfork" or "tfo". It is not possible to use regexps together with any of the if-plugins.

<set variable='' value='Sesame'/>
<if variable=' is e*,*e'>"&;" begins or ends with an 'e'.</if>
"Sesame" begins or ends with an 'e'.

Match plugins

The Match category contains plugins that match contents of something, e.g. an IP package header, with arguments given to the plugin as a string or a list of strings.

Your domain <if ip='130.236.*'> is </if>
<else> isn't </else>
Your domain isn't

State plugins

State plugins check which of the possible states something is in, e.g. if a flag is set or not, if something is supported or not, if something is defined or not etc.

   Your browser
  <if supports='javascript'>
   supports Javascript version &client.javascript;
  <else>doesn't support Javascript</else>.
Your browser doesn't support Javascript.

Utils plugins

Utils are additonal plugins specialized for certain tests, e.g. date and time tests.

  <if time='1700' after=''>
    Are you still at work?
  <elseif time='0900' before=''>
     Wow, you work early!
   Somewhere between 9 to 5.

SiteBuilder plugins

SiteBuilder plugins requires a Roxen Platform SiteBuilder installed to work. They are adding test capabilities to web pages contained in a SiteBuilder administrated site.


This tag is cache static (see the <cache> tag) if the compatibility level is set to 2.5 or higher.



Inverts the result (true->false, false->true).


If any criterion is met the result is true.


If all criterions are met the result is true. And is default.