Jelajahi Sumber

[TwigBundle] converted flash tag to a function

Fabien Potencier 14 tahun lalu
induk
melakukan
13bcf7cdac

+ 6 - 3
src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php

@@ -75,6 +75,7 @@ class TemplatingExtension extends \Twig_Extension
             'url'   => new \Twig_Function_Method($this, 'getUrl'),
             'path'  => new \Twig_Function_Method($this, 'getPath'),
             'asset' => new \Twig_Function_Method($this, 'getAssetUrl'),
+            'flash' => new \Twig_Function_Method($this, 'getFlash'),
         );
     }
 
@@ -93,6 +94,11 @@ class TemplatingExtension extends \Twig_Extension
         return $this->container->get('templating.helper.assets')->getUrl($location);
     }
 
+    public function getFlash($name)
+    {
+        return $this->container->get('templating.helper.session')->getFlash($name);
+    }
+
     /**
      * Returns the token parser instance to add to the existing list.
      *
@@ -116,9 +122,6 @@ class TemplatingExtension extends \Twig_Extension
             // {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %}
             new RenderTokenParser(),
 
-            // {% flash 'notice' %}
-            new HelperTokenParser('flash', '<name>', 'templating.helper.session', 'getFlash'),
-
             // {% include 'sometemplate.php' with { 'something' : 'something2' } %}
             new IncludeTokenParser(),
         );