mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
reintroduced _self (returns the current template name)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
* 2.0.0 (201X-XX-XX)
|
||||
* 2.0.0 (2016-XX-XX)
|
||||
|
||||
* sped up the json_encode filter
|
||||
* removed reserved macro names; all names can be used as macro
|
||||
* removed Twig_Template::getEnvironment()
|
||||
* removed _self variable (except for usage in from and import tags)
|
||||
* changed _self variable to return the current template name
|
||||
* made the loader a required argument of Twig_Environment constructor
|
||||
* removed Twig_Environment::clearTemplateCache()
|
||||
* removed Twig_Autoloader (use Composer instead)
|
||||
|
||||
@@ -127,6 +127,7 @@ Global Variables
|
||||
|
||||
The following variables are always available in templates:
|
||||
|
||||
* ``_self``: references the current template name;
|
||||
* ``_context``: references the current context;
|
||||
* ``_charset``: references the current charset.
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
class Twig_Node_Expression_Name extends Twig_Node_Expression
|
||||
{
|
||||
private $specialVars = array(
|
||||
'_self' => '$this->getTemplateName()',
|
||||
'_context' => '$context',
|
||||
'_charset' => '$this->env->getCharset()',
|
||||
);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
--TEST--
|
||||
_self returns the current template name
|
||||
--TEMPLATE--
|
||||
{{ _self }}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXPECT--
|
||||
index.twig
|
||||
@@ -21,6 +21,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase
|
||||
public function getTests()
|
||||
{
|
||||
$node = new Twig_Node_Expression_Name('foo', 1);
|
||||
$self = new Twig_Node_Expression_Name('_self', 1);
|
||||
$context = new Twig_Node_Expression_Name('_context', 1);
|
||||
|
||||
$env = new Twig_Environment($this->getMock('Twig_LoaderInterface'), array('strict_variables' => true));
|
||||
@@ -29,6 +30,7 @@ class Twig_Tests_Node_Expression_NameTest extends Twig_Test_NodeTestCase
|
||||
return array(
|
||||
array($node, "// line 1\n".'(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : $this->notFound("foo", 1))', $env),
|
||||
array($node, $this->getVariableGetter('foo', 1), $env1),
|
||||
array($self, "// line 1\n\$this->getTemplateName()"),
|
||||
array($context, "// line 1\n\$context"),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user