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 {
* name to get of the object, or the associative index to the array.
* *func1*, *func2*, etc. are helper functions that are executed in the
* 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
......@@ -300,9 +301,13 @@ class Template extends Node {
}
// Default: Simple variable name
if( !isset($value) )
if( !isset($value) ) {
$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
if( $value !== null ) {
// Apply helper functions to the variable's value iteratively
......
......@@ -224,6 +224,15 @@ class TemplateTest extends PHPUnit_Framework_TestCase {
$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
* @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