Conditional statements, or if statements or ifl statements are a core part of the Miva Merchant template language. They allow you to do powerful logical operations and are a core part of what makes Miva Merchant’s template language so powerful. Let’s dive in and look at some examples. The syntax for an if statement is always going to be mvt:if followed by a space, followed by exp=” which stands for expression, so it’s an expression that the engine will evaluate. Then you put in a condition here and if that condition is met it will execute the code.
A common use case for an if statement is to test which page or which screen you’re on in Miva Merchant. So here we can test for g.Screen, which is the current screen that’s being displayed and then we’ll say if it =, which is different than most other programming languages. Typically you would either use the double == or the triple ===, however, in Miva Merchant it’s a two letter acronym for EQ which stands for equals. So if g.Screen EQ and then we want to test for a string. Strings are always in single quotes, if g.Screen EQ ‘SFNT’” then say “This is the storefront!”
Let’s execute this over in Miva and make sure it works. I’m going to come down here to the content section and paste it. However, this code will work in any area of Miva Merchant. You can put this code in any text box in Miva and then hit “Update. “ We’ll go back to the front end now and hit “Refresh” and you’ll see here “This is the storefront.” So that’s the foundation of a Miva if statement.
Let’s take a look at some variations of it. So the if statement is the simplest and easiest conditional statement. However, there’s different variations of this. So I have some snippets set up with different variations so we don’t have to type them all out. So here is an fl statement. So it’s going to say if this condition is met execute this code, if the condition is not met, execute some other code. We also have an else:if statement which looks like this: so here it’s if the first condition is met, else if some other condition is met and you can keep nesting those as deep as you want. You can have multiple levels of else if statements with their own expression.