Commit c13df4a7 authored by Taddeus Kroes's avatar Taddeus Kroes

Added possibility to use constants in templates.

parent 878fd68e
...@@ -251,7 +251,8 @@ class Template extends Node { ...@@ -251,7 +251,8 @@ class Template extends Node {
* name to get of the object, or the associative index to the array. * name to get of the object, or the associative index to the array.
* *func1*, *func2*, etc. are helper functions that are executed in the * *func1*, *func2*, etc. are helper functions that are executed in the
* same order as listed. The retuen value of each helper function replaces * same order as listed. The retuen value of each helper function replaces
* the previous variable value. * the previous variable value. *var_name* Can also be the name of a
* defined constant.
* *
* ------------ * ------------
* If-statement * If-statement
...@@ -300,8 +301,12 @@ class Template extends Node { ...@@ -300,8 +301,12 @@ class Template extends Node {
} }
// Default: Simple variable name // Default: Simple variable name
if( !isset($value) ) if( !isset($value) ) {
$value = $data->get($name); $value = $data->get($name);
if( $value === null && defined($name) )
$value = constant($name);
}
// Don't continue if the variable name is not found in the data block // Don't continue if the variable name is not found in the data block
if( $value !== null ) { if( $value !== null ) {
......
...@@ -224,6 +224,15 @@ class TemplateTest extends PHPUnit_Framework_TestCase { ...@@ -224,6 +224,15 @@ class TemplateTest extends PHPUnit_Framework_TestCase {
$this->assert_replaces('Bar', 'FOO:strtolower:ucfirst'); $this->assert_replaces('Bar', 'FOO:strtolower:ucfirst');
} }
/**
* @depends test_replace_variable_helper_functions
*/
function test_replace_variable_constant() {
define('FOOCONST', 'foobar');
$this->assert_replaces('foobar', 'FOOCONST');
$this->assert_replaces('FOOBAR', 'FOOCONST:strtoupper');
}
/** /**
* @expectedException UnexpectedValueException * @expectedException UnexpectedValueException
* @expectedExceptionMessage Helper function "idonotexist" is not callable. * @expectedExceptionMessage Helper function "idonotexist" is not callable.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment