Home Tour Demo FAQ App Gallery Buy Now    
Home > Template Tags > How to use IF statements


How to use IF statements

{IF}

To make minor changes on the page depending on conditions, you can use IF tags.

IF tags are consist of three parts


1) Condition

2) else ( else if)

3) End


1) Condition: This is where you place your conditions, if the condition is correct then content between condition tag and if end tag will be displayed to users. If condition is not correct and "else" tag is used, content between else tag and end tag will be displayed. If else tag is not used nothing will be displayed. By this way you will have the full control of your content.


For example: You can show a link if the logged-in user is admin

{IF:admin}

     Admin Link here

{IF:end}


2) Else: if the condition is not correct, else tag displays the content between itself and if end tag. Remember, This is an optional tag. If there is no need you don't have to use it.


For example: You can show online status on user profile details


{IF:online}

  Online Image here

{IF:else}

  Offline Image here

{IF:end}



You can use else tags as second condition. Technically speaking else if If first condition doesn't match you check another condition.


For example:


{IF:admin}

   User is admin

{IF:else:accountName:Premium}

   User is premium

{IF:else}

  Regular user

{IF:end}


3) end: End tag is the closing statement of if groups. This is a must to have part of the if tags. If you forget to place {IF:end} after your if groups, page will display errors or not event work.



There are several predefined conditions you can use such as:

{IF:login} This user is logged in {IF:end}
{IF:notlogin} This user is not logged in {IF:end}
{IF:owner} This user is the owner of this profile {IF:end}
{IF:notowner} This user is not the owner of this profile {IF:end}
{IF:login} You are logged in! {IF:else} You are not logged in! {IF:end}
{IF:online} This user is online! {IF:else} This user is offline! {IF:end}
{IF:offline} This user is offline! {IF:end}
{IF:friend} You are a friend! {IF:end}
{IF:notfriend} Become a friend! {IF:end}

{IF:odd} Currently displayed entry is an ODD entry (For alternating line colors) {IF:end}

{IF:even} Currently displayed entry is an EVEN entry (For alternating line colors) {IF:end}

{IF:first} This is the first listed entry {IF:end}

{IF:last} This is the last listed entry {IF:end}

{IF:admin}
You are admin! {IF:end}
{IF:has_entry_on:article} This user has articles, click here to read them{IF:else}
{IF:has_no_entry_on:picture} This user has no picture {IF:end}
{IF:page:test.html} You are on test.html page! {IF:end}

{IF:pagenot:test.html} You are not on test.html page! {IF:end} 

{IF:folder:profile} You are under profile folder {IF:end}
{IF:foldernot:profile} You are under profile folder {IF:end}

Predefined conditions are good but you may need custom conditions, for example you may want to compare a field's value with a given value or check it was filled or not. We have implemented special IF tags for more advanced users such as:

{IFEQ:} If equals
{IFNEQ:} If not equals
{IFLT:} If less then
{IFGT:} If greater than
{IFLTEQ:} If less then or equal
{IFGTEQ:} If greater than or equal
{IFINC:} If includes

These conditions are specifically build to match a fields value with a given value. Here are some useful examples

{IFLTEQ:age:18} Checks if users age is 18 or less.
{IFEQ:profilePicture:} Checks if profile picture is blank.
{IFEQ:state:USA} Checks if users state is USA
{IFINC:address:New York} Checks if users address contains "New York" in it.
{IFNINC:address:New York} Checks if users address does not contain "New York" in it.




Tags: template tags
Related Articles:


Add a new comment

Send Comment

 
 
Customer Log-in | Support Forums | User Guide | Free Form Builder | Contact Memberkit Team