|
|
@@ -71,10 +71,12 @@ require_once 'node.php';
|
|
|
* curly brackets: *{expression}*. The grammar of all expressions that are
|
|
|
* currently supported can be described as follows:
|
|
|
* <code>
|
|
|
- * <expression> : {<nested_exp>}
|
|
|
- * | {<nested_exp>?<nested_exp>:<nested_exp>} # Conditional statement
|
|
|
+ * <expression> : {<exp>}
|
|
|
+ * <exp> : <nested_exp>
|
|
|
+ * | <nested_exp>?<nested_exp>:<nested_exp> # Conditional statement
|
|
|
* <nested_exp> : <variable>
|
|
|
- * | <function>(<nested_exp>) # Static function call
|
|
|
+ * | <nested_exp>||<nested_exp> # Default value
|
|
|
+ * | <function>(<nested_exp>) # Static function call
|
|
|
* | <constant>
|
|
|
* | <html>
|
|
|
* <variable> : $<name> # Regular variable
|
|
|
@@ -83,7 +85,7 @@ require_once 'node.php';
|
|
|
* <function> : <name> # Global function
|
|
|
* | <name>::<name> # Static class method
|
|
|
* <constant> : An all-caps PHP constant: [A-Z0-9_]+
|
|
|
- * <html> : A string without parentheses, curly brackets or semicolons: [^(){}:]*
|
|
|
+ * <html> : A string without parentheses, pipes, curly brackets or semicolons: [^()|{}:]*
|
|
|
* <name> : A non-empty variable/method name consisting of [a-zA-Z0-9-_]+
|
|
|
* </code>
|
|
|
*
|
|
|
@@ -423,6 +425,13 @@ class Template extends Node {
|
|
|
} elseif( preg_match("/^([A-Z0-9_]+)$/", $expression, $matches) ) {
|
|
|
// <constant>
|
|
|
return self::evaluate_constant($expression, $root_level);
|
|
|
+ } elseif( ($split_at = strpos($expression, '||', 1)) !== false ) {
|
|
|
+ // <nested_exp>||<nested_exp>
|
|
|
+ try {
|
|
|
+ return self::evaluate_expression(substr($expression, 0, $split_at), $data, false);
|
|
|
+ } catch(\RuntimeException $e) {
|
|
|
+ return self::evaluate_expression(substr($expression, $split_at + 2), $data, false);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|