24/7 Support: 800.608.6482

Developer Docs

Template Language

else Statement

If Else Statement

We've got the hang of if statements now. We check a condition, and if it's true, we execute some code. That works, and it's very handy, but what if we want to run some code if the condition is false? That's where the if-else statement comes in handy, it looks exactly like if statement, but before the statement closes, we can add , this gives us the option to run some different code if the first if statement is NOT true.

The code for an if-else statement looks like this:

The above code is the exact same as our original if statement, except now we have added some code to execute if the original condition is false. If we are on the Storefront page, we will see "Welcome to our awesome site!", but if we are on ANY other page besides SFNT, we will see a nice promotion for our sale on men's shirts.

elseif Statement

The statement can accomplish the same goal as writing two separate if statements, but why do that when we can simply combine it into one section? Using the elseif statement is simple, you open an if statement, check if a condition is true, then rather than exiting the if statement, we can check another condition with elseif.

The code for an elseif statement looks like this:

If you look at the code above, you'll notice that we are checking for the same condition as our original if statement, is the current Screen the SFNT. Immediately following that statement, rather than close the if statement, we put an elseif right after it. This time, we check if the Screen is PROD, if it is, we display a message about free shipping. If neither of those conditions are met, we exit the if statement and don't run any code at all. You can chain as many elseif together as your little heart desires.

This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

Accept

Copyright © 1997 – 2023 Miva©, Miva Merchant©, MivaPay©, MivaCon©, Camp Miva ℠, Miva, Inc. All Rights Reserved.