mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 02:26:41 +03:00
Merge pull request #112 from majortom731/master
@root special variable like in handlebars-v2.0.0.js
This commit is contained in:
commit
c0c58a2a85
@ -203,6 +203,10 @@ class Context
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
if (substr($variableName, 0, 6) == '@root.') {
|
||||||
|
$variableName = trim(substr($variableName, 6));
|
||||||
|
$level = count($this->stack)-1;
|
||||||
|
}
|
||||||
end($this->stack);
|
end($this->stack);
|
||||||
while ($level) {
|
while ($level) {
|
||||||
prev($this->stack);
|
prev($this->stack);
|
||||||
|
@ -1226,6 +1226,33 @@ EOM;
|
|||||||
$this->assertEquals($res, $results);
|
$this->assertEquals($res, $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rootSpecialVariableProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('{{foo}} {{ @root.foo }}', array( 'foo' => 'bar' ), "bar bar"),
|
||||||
|
array('{{@root.foo}} {{#each arr}}{{ @root.foo }}{{/each}}', array( 'foo' => 'bar', 'arr' => array( '1' ) ), "bar bar"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test 'root' special variable
|
||||||
|
*
|
||||||
|
* @param string $template template text
|
||||||
|
* @param array $data context data
|
||||||
|
* @param string $results The Expected Results
|
||||||
|
*
|
||||||
|
* @dataProvider rootSpecialVariableProvider
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testRootSpecialVariableHelpers($template, $data, $results)
|
||||||
|
{
|
||||||
|
$engine = new \Handlebars\Handlebars();
|
||||||
|
|
||||||
|
$res = $engine->render($template, $data);
|
||||||
|
$this->assertEquals($res, $results);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user