Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webbasics
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webbasics
Commits
c13df4a7
Commit
c13df4a7
authored
Jul 15, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added possibility to use constants in templates.
parent
878fd68e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
template.php
template.php
+7
-2
tests/test_template.php
tests/test_template.php
+9
-0
No files found.
template.php
View file @
c13df4a7
...
@@ -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,9 +301,13 @@ class Template extends Node {
...
@@ -300,9 +301,13 @@ 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
)
{
// Apply helper functions to the variable's value iteratively
// Apply helper functions to the variable's value iteratively
...
...
tests/test_template.php
View file @
c13df4a7
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment