Skip to main content

<CSP:IF>

Delimits an IF block.

Synopsis

<CSP:IF>...</CSP:IF>

Attributes

General Attributes

Attribute Description Value
CONDITION A runtime COS expression to be evaluated. A server-side expression.

Description

The CSP:IF tag displays its contents if the server–side expression specified by the CONDITION attribute evaluates to TRUE at runtime.

A CSP:IF tag must have a CONDITION attribute.

You can specify additional execution paths using the CSP:ELSEIF and CSP:ELSE tags.

You can nest CSP:IF tags:

<CSP:IF CONDITION="a=10">
  <CSP:IF CONDITION="b=20">
  <VAR>a</VAR> = 10 and <VAR>b</VAR> = 20.
  </CSP:IF>
</CSP:IF>

CSP:IF Examples

The following displays different messages depending on the NAME URL parameter (obtained via the %CSP.RequestOpens in a new tab object):

<CSP:IF CONDITION='$G(%request.Data("NAME",1))="John"'>
Welcome, John!
<CSP:ELSEIF CONDITION='$G(%request.Data("NAME",1))="Jane"'>
Welcome, Jane!
<CSP:ELSE>
Welcome, whoever you are!
</CSP:IF>

The following example tests if the %session object contains a value for USERNAME . If not it places an error message on the document:

<CSP:IF CONDITION='(%session.Get("USERNAME")="")'>
        Unauthorized Access!
        </CSP:IF>

Specifying Script Language

The CSP:IF tag will fire one of two rules depending on whether the language is set to cache or basic; these two rules are %IF and %IFBASIC.

FeedbackOpens in a new tab