From: Fabien Potencier Date: Sat, 20 Nov 2010 13:43:35 +0000 (+0100) Subject: added _charset as a special variable that references the current charset X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=4778822863783d450241685f3f2992c128d7f982;p=konrad%2Ftwig.git added _charset as a special variable that references the current charset --- diff --git a/CHANGELOG b/CHANGELOG index 02eae89..f9f56fa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -34,6 +34,7 @@ Backward incompatibilities: * removed the debug tag (should be done in an extension) * fixed trans tag when no vars are used in plural form * fixed race condition when writing template cache + * added the special _charset variable to reference the current charset * added the special _context variable to reference the current context * renamed self to _self (to avoid conflict) * fixed Twig_Template::getAttribute() for protected properties diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index 4a9d801..5ab7508 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -105,10 +105,11 @@ If a variable or attribute does not exist you will get back a `null` value > [twig] > foo[bar] -Twig always references two special variables (mostly useful for macros): +Twig always references the following variables: * `_self`: references the current template (was `self` before 0.9.9); - * `_context`: references the current context. + * `_context`: references the current context; + * `_charset`: references the current charset (as of 0.9.9). Filters ------- diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index c4a3acd..37cd727 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -22,6 +22,8 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression $compiler->raw('$this'); } elseif ('_context' === $this->getAttribute('name')) { $compiler->raw('$context'); + } elseif ('_charset' === $this->getAttribute('name')) { + $compiler->raw('$this->getEnvironment()->getCharset()'); } elseif ($compiler->getEnvironment()->isStrictVariables()) { $compiler->raw(sprintf('$this->getContext($context, \'%s\')', $this->getAttribute('name'), $this->getAttribute('name'))); } else {