<if> ... </if> |

`<if>` is defined in the Main RXML parser module.

`<if>` is used to conditionally show its contents. `<else>`, `<elif>` or `<elseif>` can be used to suggest alternative content.

It is possible to use glob patterns in almost all attributes, where * means match zero or more characters while ? matches one character. * Thus `t*f??` will match `trainfoo` as well as * `tfoo` but not `trainfork` or `tfo`.

Attributes |
accept, config, cookie, date, defined, domain, eval, exists, filename, host, language, match, name, prestate, referrer, supports, time, user, variable, after, and, before, file, group, inclusive, wwwfile, not, or,

Attributes

`accept`=type1[,type2,...]
  Returns true is the browser accept certain content types as specified by it's Accept-header, for example image/jpeg or text/html. If browser states that it accepts */* that is not taken in to account as this is always untrue.

`config`=name
  Has the config been set by use of the `<aconf>` tag?

`cookie`=name[ is value]
  Does the cookie exist and if value is given, does it contain the value value?

`date`=yyyymmdd
  Is the date yyyymmdd? The attributes `before`, `after` and `inclusive` modifies the behavior.

`defined`=define
  Is the define defined?

`domain`=pattern[,pattern...]
  Does the users computer's DNS name match any of the patterns? Note that domain names are resolved asynchronously, and the the first time someone accesses a page, the domain name will probably not have been resolved.

`eval`=RXML expression
  Returns true if `RXML expression` returns a string that evaluates to true if casted to an integer in Pike, i.e. the string begins with 1-9 or a number of zeroes followed by 1-7 (octal greater than zero).

  Future versions of Roxen (starting from version 1.4) will evaluate to true on a number of zeroes followed by 1-9 (decimal greater than zero).

`exists`=path
  Returns true if the file `path` exists. If `path` does not begin with /, it is assumed to be a URL relative to the directory containing the page with the `<if>`-statement.

`filename`=filepattern1[,filepattern2,...]
  Returns true if the current page is among the listed filepatterns.

`host`=pattern[,pattern...]
  Does the users computers IP address match any of the patterns?

`language`=language1[,lang2,...]
  Does the client prefer one of the languages listed, as specified by the `Accept-Language` header?

`match`=string[ is pattern[,pattern,...]]
  Does the string match one of the patterns?

`name`=pattern[,pattern...]
  Does the full name of the browser match any of the patterns?

`prestate`=option1[,option2, ...]
  Are all of the specified prestate options present in the URL?

`referrer`=[=pattern[,pattern,...]]
  Does the referrer header match any of the patterns?

`supports`=feature
  Does the browser support this feature? See the support feature page page for a list of all available features.

`time`=ttmm
  Is the date ttmm? The attributes `before`, `after` and `inclusive` modifies the behavior.

`user`=name[,name,...]|any
  Has the user been authenticated as one of these users? If any is given as argument, any authenticated user will do.

`variable`=name[ is pattern]
  Does the variable exist and, optionally, does it's content match the pattern?

Modifier Attributes

`after`

  Used together with the `date` attribute.

`and`

  If several conditional attributes are given all must be true for the contents to be shown. This is the default behavior.

`before`

  Used together with the `date` attribute.

`file`=path
  Used together with the `user` attribute. An external file will be used to authenticate the user, rather than the current Authentication module. The file should have the following format:

      user name : encrypted password
      user name : encrypted password

  Unless the `wwwfile` attribute is given the path is a path in the computers real file system, rather than Challenger's virtual file system.

`group`=group, groupfile path
  Used together with the `user` attribute to check if the current user is a member of the group according the the groupfile. If groupfile is not specified, the internal user databases will be searched for group membership. The groupfile is of the following format:

      group : user1, user2, user3
      group : user4

`inclusive`

  Used together with the `date` and `before` or `after` attributes. The contents will also be shown if the date is the current date.

`wwwfile`

  Used together with the `file` attribute to indicate what Challenger's virtual file system should be used to find the password file. This might be a security hazard, since anyone will be able to read the password file.

`not`

  Inverts the results of all tests.

`or`

  If several conditional attributes are given, only one of them has to be true for the contents to be shown.

Complex expressions

You might be tempted to write expressions like:

<doc>`{if variable="foo is bar" or variable="bar is foo"}Something{/if}`</doc>

This will not work, as you can only use an attribute once.

Another common problem is a misconception of how the `and`, `or` and `not` attributes work.

<doc>`{if user=foo or not domain="*.foobar.com"}...{/if}`</doc>

will not work since the `not` attribute negates the whole tag, not just the `domain` attribute.

Example

source code

    Your browser supports tables.

    "=> >

result | Your browser supports tables.

source code

    You are logged in.

    <else>
    You are not logged in.
    </else>

    "=> >

result | You are logged in. <else> You are not logged in. </else>

source code

    The year 2000 is yet to come.

    "=> >

result | The year 2000 is yet to come.