Expressions

The Nest expression language used the jstl expression language as a jumping off point, but tries to be as PHP as possible. Since php has methods like __get and __set there didn't seem to be any point to using bean introspection like java.

Expressions can be between the token tags ${}, or in tag attributes without the tags. The syntax is just like PHP except that attributes are specified without the leading $.

You can specify html text that shouldn't be escaped with #{}. Be aware that doing so can potentially leave you exposed to XSS attacks. Be sure you cleanse the data you're presenting this way.

Simple Variables

The simplest form of the expression language are simply outputting variables as we've prevously introduced. The name will be the key when adding the attribute to the view.

$view->addAttribute("myVariable", "myValue");
${myVariable}
Output: myValue

Array Variables

Arrays are accessed just like in php.

Indexed
$view->addAttribute("myArray", Array("apples", "bananas", "oranges"));
${myArray[1]}
Output: bananas

Associative
$view->addAttribute("myArray", Array("a" => "apples", "b" => "bananas", "o" => "oranges"));
${myArray["b"]}
Output: bananas

Object Variables

Public object members and methods are accessed just like in php.

Member
${myObject->name}
${myObject->key}
Method
${myObject->getName()}
${myObject->execute()}
Nested
${myObject->getParent()->execute()}

Math

Mathematical expressions can be done just like in PHP.

${1 == 1}
${1 == 0}
${myVar % 5}
${(1000 * 50) / myvar}
${myvar->price * myvar->tax}

Conditional

Conditional expressions can be evaluated just like in PHP.

${1 == 1 || myVar == 'bob'}
${1 == myVar && access == 'admin'}
${rowcount % 2 ? 'green' : 'red'}