Merge pull request #127 from thormeier/partial-support-and-error-reporting

Fix handling of named arguments in partials
This commit is contained in:
Dmitriy Simushev 2015-06-30 21:02:40 +03:00
commit 10dbe6442e
2 changed files with 11 additions and 4 deletions

View File

@ -538,7 +538,12 @@ class Template
} }
} }
return array_merge($positionalArgs, $arguments->getNamedArguments()); $namedArguments = array();
foreach ($arguments->getNamedArguments() as $key => $value) {
$namedArguments[$key] = $context->get($value);
}
return array_merge($positionalArgs, $namedArguments);
} }

View File

@ -722,6 +722,11 @@ EOM;
) )
); );
$this->assertEquals('foobar', $engine->render("{{>presetVariables myVar='foobar'}}", array()));
$this->assertEquals('foobar=barbaz', $engine->render("{{>presetVariables myVar='foobar=barbaz'}}", array()));
$this->assertEquals('qux', $engine->render("{{>presetVariables myVar=foo}}", array('foo' => 'qux')));
$this->assertEquals('qux', $engine->render("{{>presetVariables myVar=foo.bar}}", array('foo' => array('bar' => 'qux'))));
$this->assertEquals('HELLO', $engine->render('{{>test parameter}}', array('parameter' => array('key' => 'HELLO')))); $this->assertEquals('HELLO', $engine->render('{{>test parameter}}', array('parameter' => array('key' => 'HELLO'))));
$this->assertEquals('its foo', $engine->render('{{>foo}}', array())); $this->assertEquals('its foo', $engine->render('{{>foo}}', array()));
$engine->registerPartial('foo-again', 'bar'); $engine->registerPartial('foo-again', 'bar');
@ -730,9 +735,6 @@ EOM;
$this->setExpectedException('RuntimeException'); $this->setExpectedException('RuntimeException');
$engine->render('{{>foo-again}}', array()); $engine->render('{{>foo-again}}', array());
$this->assertEquals('foobar', $engine->render("{{>presetVariables myVar='foobar'}}", array()));
$this->assertEquals('foobar=barbaz', $engine->render("{{>presetVariables myVar='foobar=barbaz'}}", array()));
} }
/** /**