VWcms Conditional Content  
 

[PREV][NEXT]

[PRINT]

The $$IF$$ directive evaluates the request environment and then conditionally processes (and outputs) content between it and a matching $$ELSE$$ and/or $$ENDIF$$.  Conditionals may be nested, and can be used in both the site template and content.  Obviously it is intended to allow tailoring of that content.  One example might be the inclusion of a coversheet with a printed version.

$$IF$!print$$$$HIDE$$

Conditionals expressed in the template apply to the template and those in content apply to the currrent section of content only.  There is no global conditional scope.  The conditional above when placed on the first line of the section hides it if not printing.

$$IF$login$$
$$IF$login=mark daniel$$
This is some information specifically for MGD!
$$ELSE$$
General information for logged-in users.
$$ENDIF$$$$ENDIF$$

There are no fixed layout requirements for conditionals.  All on a single line or across multiple lines as applicable is fine.  Be aware unexpected white-space may be included in the document (most times to no consequence).

Evaluation

The $$IF$$ directive should be provided with a parameter.  Without a parameter it evaluates to false.

Parameter Content Description
cgi= name=keyword
If the named CGI variable exists and its value contains the specified keyword (string) then true.  If the CGI variable does not exist or does not contain the keyword then false.  In addition string comparison operators are available for testing CGI variables - see below.
lnm= name=keyword
If the specified logical name exists (case-sensitive) and its value contains the specified keyword (string) then true.  If the logical name does not exist or does not contain the keyword then false.  In addition string comparison operators are available - see below.
login none
If the current request is logged-in.
login= username If currently logged-in and it matches the supplied username.
manage none If currently in site management mode.
manage= "edit" If currently in site management edit mode.
print none If currently printing.
print= scope If currently printing the site ("ALL"), the current page "(PAGE") or the page plus subordinates ("PAGE+").
query= keyword if the query string begins with the specific keyword (e.g. login, tag).
rss none
If currently providing an RSS feed.
rss= feed If currently providing the specified RSS feed name.
search none If currently undertaking a keyword search.
0 none unconditionally false
1 none unconditionally true

A parameter can be prefixed by a "!" to logically negate the result; so "!0" is true and "!print" is false when printing.  Multiple parameters separated by '$' symbols (as is usual with multiple directive parameters), acting as a logical OR.  Hence if any one of mutliple parameters evaluates true then the entire conditional is true.  A parameter may be prefixed by ''&&" to make the result a logical AND with any preceding result.  No nesting of logical operations is supported.

The conditional

$$IF$cgi=http_user_agent=Opera$&&print$$

would be true only if printing via the Opera browser, whereas

$$IF$cgi=http_user_agent=Opera$cgi=http_user_agent=Mozilla$&&!print$$

would be true if using either Opera or a Mozilla (family) browser and not printing.

String Evaluation

The following operators provide more granular tests based on string comparison.  All are case-insensitive.

Operator Description Syntax
== Equality
$$IF$cgi=WWW_FORM_INDEX==10$$
<> or !=
Inequality $$IF$cgi=WWW_FORM_INDEX<>10$$
< Less than $$IF$cgi=WWW_FORM_INDEX<9$$
> Greater than $$IF$cgi=WWW_FORM_INDEX>11$$
<= Less than or equal to $$IF$cgi=WWW_FORM_INDEX<=9$$
>= Greater than or equal to $$IF$cgi=WWW_FORM_INDEX>=11$$
= Substring match.  It locates the specified substring in the CGI variable's value. $$IF$cgi=WWW_FORM_INDEX<=>11$$
^ Regular expression match.
See Regular Expressions.
$$IF$cgi=WWW_FORM_INDEX^fred|wilma$$

Dynamic Examples

The following examples use conditionals to tailor displayed content.  What you see will vary on browser in-use and other request characteristics.

For example, you won't see this sentence on a printed page!

$$IF$cgi=http_user_agent=MSIE$$ results in something most probably much more standards compliant (non-MSIE) .  This is based on a user-agent of "CCBot/2.0".

$$IF$login$$ restricts content to those who are currently logged-in.

$$IF$lnm=VWCMS_ROOT$$ tells us that your system is currently using the VWCMS_ROOT logical name.

[PRINT]  [PRINT]