24/7 Support: 800.608.6482

Get Started

Videos | Conditional Statements

ver. 9.0 and later

Video Transcript

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.



Example Code

Reference Documentation




comments powered by Disqus

Looking for Developer Docs?

We have a whole section for that, including: Developer Training Series, Template Language docs, Module Development tutorials and much, much more.

Head to the Developer Section

Miva believes that all online businesses should have access to a scalable ecommerce platform that can meet their unique business requirements. Miva offers PCI compliant ecommerce, hosting, and custom website design and development solutions. Miva customers have processed over $100 billion in online sales since 1997.

Copyright © 2016 Miva, Inc - All Rights Reserved   Privacy Policy | Store Policy

Links
Contact Us
Receive Tips & Updates

Copyright © 2017 Miva, Inc - All Rights Reserved

Back To The Top