Welcome

BoltWire is a FREE content management system written in PHP.

Its innovative architecture combined with best-in-class forms processing gives surprizing power in the tiniest of footprints.

Our software is ideal for creating complex, interactive, web applications fast...

Conditions

Documentation > Handbook > Conditions

Conditionals allow you to customize site content dynamically based on various criteria.

Here's a list of conditionals currently available in BoltWire. Click one for more info:

abort
admin
auth
between
editor
equal
exists
false
ingroup
inlist
inpage
insource
less
login
mobile
more
new
number
print
set
stamp
submit
time
true

How to Use

Here is an example of how to use a conditional. It checks to see if the current user is logged in, and if so, gives them a welcome message.

[if login]Welcome {id}[if]

Here's how to use the "if / else" feature:

[if login]Welcome {id}[else]You are a Guest[if]

Some conditions require parameters:

[if more 7 5]True[if]

You can also use negation:

[if ! login]Please login to continue[if]

You can also use the operators && (and) and || (or). You can also use parentheses to form more complicated expressions:

[if login && mobile]Some mobile text for logged in users[if]

[if login && (more {var1} 10 || more {var2} 20)]Some text[if]

You can nest conditionals like this:

[if login][if admin]Logged in Admin[else]Logged in Member[if][else]Not logged in[if]

Note: Make sure you close all conditionals or it will cause problems with the display.

Advanced Features

In version 6.0 we added a switch parameter which comes in handy if you have a page with complex branching conditionals. Basically the first true match is displayed, and all subsequent matching cases automatically return false. You can set the switch id to any value desired.

[if cond 1 switch=show]ONE[if]
[if cond 2 switch=show]TWO[if]
[if cond 3 switch=show]THREE[if]
[if true 4 switch=show]FOUR[if]

If two returns true, the display will show "TWO" and four will not be shown even though it is always true. By setting the last condition to true, we know every viewer will see that option if every other option fails.

Conditions in commands and functions

Conditionals can be used in both commands and functions as a simple parameter to control whether the command is implemented or the function executed. For example:

[(breadcrumb if='! mobile')]

This will show a breadcrumb trail only if the user is not seeing the mobile display.

Conditions in search functions

Conditionals can be used in search and list functions to filter which matches are processed, using the "when" parameter. The following example returns all member pages where the second page part is between c and f. Notice the template variable used here.

[(search group=member* when='between c {+p2} f')]

Regular if conditionals can also be used in templates and formats for your search display.

The if command

There is an 'if' command that allows you to tap into the conditional engine through the forms processing engine. It is described in more detail in the commands tutorials, but here is a simple example:


[form]
[radio color red] Red   [radio color blue] Blue
[submit]
[command if "equal {=color} red ? warn='Don't pick this one!'"]
[command warn]
[form]

This basically assigns a value to the warn command if you choose the red radio button. That causes the form to abort and the warning message is given. You can use any conditional with this command.

Order of operations

It is important to remember the order of operations when using conditionals with functions. The <(function)> markup is designed to process AFTER the conditionals, where as the other functions are processed BEFORE conditionals.

This means the first two examples will forward despite failing the conditional, because the function is processed before the conditional is checked. The second one will work as expected:

[if false]{(forward some.page)}[if]
[if false][(forward some.page)][if]
[if false]<(forward some.page)>[if]

Similarly, the first two functions below will work as expected because the parameters are correctly supplied before the conditional is checked. The latter will not work properly, because the conditional is checked before the function value is retrieved.

[if equals {(function)} true]TRUE[if]
[if equals [(function)] true]TRUE[if]
[if equals <(function)> true]TRUE[if]

Or consider the example below. In both situations, the markup will display properly, but first one wastes processing time. That is because while only the first search is shown, both searches are performed. The second one does the conditional first, and then only processes the correct search.

[if true][(search group=alpha)][else][(search group=beta)][if]
[if true]<(search group=alpha)>[else]<(search group=beta)>[if]

Toolmapping.

Toolmapping allows you to point a default conditional to a custom script, effectively overwriting the default behavior of the command. Suppose you wanted to customize how the filter conditional works. Simply add the following line to index.php or config.php or a plugin, and when the conditional time is called, BoltWire will reroute the parameters to BOLTCmyfilter (your script), rather than BOLTCfilter (the default script):

$BOLTtoolmap['c']['filter'] = 'myfilter';

It also works the opposite way. The following line would essential create a new "myfilter" conditional that maps to the default filter conditional and works exactly the same:

$BOLTtoolmap['c']['myfilter'] = 'filter';

Toolmapping is a very powerful feature for customizing how BoltWire works. BoltWire can also remap functions (change the 'c' to 'f') and commands (change the 'c' to 'x').

Developer Information

All the conditionals available to BoltWire are included in conditions.php and they are arranged in alphabetical order. There are several markup rules associated with conditionals in markup.php. And the functions that process the conditionals are found in library.php.

To develop a custom conditional simply create a function prefixed by BOLTC modeled on one similar to your needs. Then add it to the config.php file or a plugin. It then becomes instantly available to your site. The following php function allows you to use the markup below it.


function BOLTCfriday($args) {
     if (strftime('%A') == 'Friday') return true;
     }

[if friday]Today is Friday[if]

If you create a custom conditional it can be combined with other conditionals and automatically inherits all the nesting, negation, and boolean capabilities of normal conditionals.

If you develop an especially useful conditional consider posting it to our mailing list so we can put it in the Extensions area and share it with others.