docs.roxen.comView this page in a printer friendly mode
DocsRoxenWebServer 6.1Web Developer ManualIf Tags
Copyright  2018, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com
 DEMO  DOCS  PIKE
 COMMUNITY  DOWNLOAD
www.roxen.com



<else>
<elseif>
<false>
<if>
<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 recaptcha-verify>
<if referrer>
<if scope>
<if sizeof>
<if supports>
<if time>
<if true>
<if type-from-data>
<if type-from-filename>
<if user>
<if variable>
<if Variable>
<if variable-exists>
<then>
<true>

<if></if>

Provided by module: Tags: RXML 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 provided attributes 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. </if>

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. </if> </if>

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='var.foo > 0' and='' match='var.bar is No'> ... </if>
<if variable='var.foo > 0' not=''> &var.foo; is less than 0 </if><else> &var.foo; is greater than 0 </else>

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 split 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='var.name' value='Sesame'/> <if variable='var.name is e*,*e'>"&var.name;" 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> liu.se.
Your domain isn't liu.se.

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; </if> <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? </if> <elseif time='0900' before=''> Wow, you work early! </elseif> <else> Somewhere between 9 to 5. </else>

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.

Note!

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


Attributes

not

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


or

If any criterion is met the result is true.


and

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