Prev |  | Next

#### 1.4.4.5. IF .. ELSEIF .. ELSE ..

Function

  Using these statements, you can control if certain blocks of code in your template are processed or not, based on a given `<CONDITION>`. This can for example be useful if you want certain parts of the page to be only visible for registered users.

Syntax

  `
  {IF <CONDITION>}
  .. conditional code ..
  [{ELSEIF <CONDITION>}
  .. conditional code ..]
  [{ELSE}
  .. conditional code ..]
  {/IF}
  <CONDITION> Syntax: [NOT] <TEMPLATE VARIABLE> [<VALUE>]
  `

  The `<TEMPLATE VARIABLE>` in a `<CONDITION>` has to be an existing variable name. The `<VALUE>` can be any of the data types that are supported by the template language (see Section 1.4.3, “Data types”).

  If a `<VALUE>` is used, the `<TEMPLATE VARIABLE>` will be compared to the `<VALUE>`. If the `<VALUE>` is omitted, then the condition will check whether the `<TEMPLATE VARIABLE>` is set and not empty.

  A condition can be negated by prepending the keyword `NOT` to it.

  Multiple conditions can be chained using the keywords `AND` or `OR`.

Example code

  Example 1.17. IF .. ELSEIF .. ELSE .. statement usage

      {IF NOT LOGGEDIN}
         You are currently not logged in.
      {ELSEIF USER->username "John"}
         Hey, it's good to see you again, mr. John!
      {ELSE}
         Welcome, {USER->username}!
      {/IF}

      {IF ADMINISTRATOR true OR USER->username "John"}
         You are either an administrator or John.
      {/IF}

      {IF VARIABLE1 VARIABLE2}
         Variable 1 and 2 have the same value.
      {/IF}

Prev | Up | Next
| Home |