Users Anywhere allows you to use if-else structures inside the {users}
tag.
The if structures tag syntax looks like:
{if ...}...{elseif ...}...{else}...{/if}
You can use pretty much any Data Type inside the if conditions. Especially the Numbers are very useful, as we have seen above.
Check if the data exists or not
You can check whether a data exists (meaning it's NOT empty or false) or not. For instance, to show a line mentioning the favorite book only if the user has something in the 'favoritebook' field, you can do:
{if favoritebook}My favorite book is: [favoritebook]{/if}
If you want to show a different readmore text when the user doesn't have a favorite book, you can do:
{if favoritebook}My favorite book is: [favoritebook]{else}I hate books!{/if}
Or the opposite, you can place specific content if the data doesn't exist (meaning it's empty or false):
{if !favoritebook}...{/if}
Check value of the data
Or check if a data is (or is not) equal to a certain value, like:
{if id = 62}...{/if}
{if name != Peter van Westen}...{/if}
Users Anywhere's If Structures support these comparison operators:
=
Equal!=
Not equal<
Less than>
Greater than<=
Less than or equal to>=
Greater than or equal toIN
Value is found in the list of values. Example:{if 'Customer' IN usergroups}
or{if color IN ['blue', 'red', 'green']}
NOT IN
Value is not found in the list of values
Multiple Conditions
You can also place multiple conditions in one {if}
tag.
If all of the conditions should pass, separate the conditions with AND
or &&
.
If any of the conditions should pass, separate the conditions with OR
or ||
.
{if country = 'Belgium' && 'Customer' IN usergroups}I'm a customer from Belgium{/if}
{if habitat-area = "Asia" || habitat-area = "America"}This user thrives best in Asia or America{/if}
Custom Fields PRO
You can also base your if conditions on custom field values, by simply using the custom field name - for example:
{if nr-of-legs}...{/if}
Normally when using {if}
tags with custom field values, the condition will check the raw value of the custom field (as saved in the database).
But in certain cases, such as lists or checkbox fields, you might want to check against the text value of the custom field instead. You can do so by adding :output
after the name of the field:
{if nr-of-legs:output}...{/if}
Nested If Structures PRO
Normally, you can only use one level of If Structures, meaning you can't nest If tags inside other If tags.
However, if you would like to use nested if structures, you can do so by taking advantage of the Nested Users Tag.
You can simply wrap your nested set of {if}
tags in a nested {user}
or {users}
tag. For example:
{users usergroup="Customer" separator="<hr>"} <h4>[name]</h4>
{if nr-of-legs = 3}
I have 3 legs.
{user-nested id="[id]"}
{if 'furry' IN my-specs}
I am also also furry.
{elseif 'fluffy' IN my-specs}
I am also very fluffy.
{/if}
{/user-nested}
{/if}
{/users}
For full control via PHP, you could also use Sourcerer to output the {users}
tag depending on your custom checks.