Maple Engine

Last Updated: 2023-11-04 06:02:43
Condition statements are a way to evaluate variables perform a specific action usually by adding HTML or CSS classes.  Conditions also support the else statement which executes an alternative action if the condition is not met.  A condition consists of three parts, the variable or collection, operators, and values.  It's also possible to use functions within condition statement which we'll get to later.
Conditions use the same access methods as defined for variables including optional quotes for collection data.  There is one small difference, independent brackets are not included.  Lets go over some of the basics of variables and how to access them.
        
Variables are defined as { [ VARIABLE ] } where VARIABLE is the name of a variable.  To access its value is written as { myVariable }
    
A collection and it's keys, often referred to as a record-set, are accessed differently and requires the indication of a key name.  Keys are indicated through brackets and optional quotes enclosing the key name.
    
For example, a variable representing an account may have first and last name variables.  These values can be accessed as myAccount['FirstName'] or myAccount['LastName'].  You can use single, double or no quotes so myAccount['FirstName'] is the same as myAccount["FirstName"] and myAccount[FirstName].
     
An operator sets the rule of the evaluation, it compares a one value to another and evaluates whether the condition is positive or negative.  The possible comparison expressions are =, <, >, !=, <=, or >=.  Maple is flexible with the equals operator and allows it to be written as either =, == or ===  Each of these are the same.
    
Note: An operator can also compare one variable to another.
When an operator performs a comparison, the values being compared must be of the same type.  The type can be textual or numeric.  If  comparing textual values then they must be enclosed in either double or single quotes, otherwise, execution will stop and your template will only be partially rendered.  Quotes are only required if the value is explicitly defined.
        
Note: Values can also be variables.
Conditions are defined as either having a single action or also an alternative action.  Let's look at the definition and some examples.
    
{ [ VARIABLE ] [ OPERATOR ] [ VARIABLE|VALUE ] } ... { end }
{ [ VARIABLE ] [ OPERATOR ] [ VARIABLE|VALUE ] } ... { else } ... { end }

        
Examples

{ myVariable >= 3 } ... { end }
{ myAccount[FirstName] != "John" } ... { end }
{ myAccount[FirstName] = myAccount[LastName] } ... { end }
{ myAccount[FirstName] === myAccount[LastName] } ... { end }
        
The second example requires quotes because John is explicitly defined.

The third and fourth examples are the same.
Conditions also support the use of functions within its declaration.  A function is a unit of code which performs actions to accomplish a specific task.  A typical function optionally accepts parameters and may have a return value.
        
Maple allows you to write HTML templates using placeholders for functions.  A Maple function will always accept one parameter and always returns a value.  The value returned usually is either an evaluation or modification of the parameter accepted.
        
Maple functions are identified by a name and brackets and are defined as FUNCTION( PARAMETER ) where FUNCTION is the maple function name and PARAMETER is a variable passed to it.  For example, length( myVariable ) or show( myVariable )
        
Let's look at some examples of using functions within conditions.  A list of functions and their meaning is discussed later.
        
{ count( accounts ) >= 1 } ... { end }
{ defined( myAccount[FirstName] ) = 1 } ... { end }

        
Note: All available functions are pre-defined, it is not possible to define your own.
Was this page helpful?