function

EVML supports creation of basic function declarations within a single and unbroken <?ev..?> script block.

Syntax


    function name([parameter [..., parameter]]){
        statement;
        [return [expression];]
    }

Where...

name The function name.
parameter The name of an argument to be passed to the function.
statement The statements to be executed when the function is called.
return Optionally you can return from the function causing the function to terminate.
expression The expression to return.


Example

<?ev
    function hello(name){
        return 'Hello ' + name;
    }
    print(hello('Bob'));
?>

Function expressions

It is also possible to create a function using an expression. The main difference between a function expression and a function statement is the function's name can be omitted to create anonymous functions.

<?ev
    var person = {
        hello: function(name){
            return 'Hello ' + name;
        }
    };
    print(person.hello('Bob'));
?>

Note EVML is a template language, function support is fairly primitive and restricted to the scope of the template. This means you cannot currently include a file containing a function for use in another template. Functions do not currently support parameters with default values.