|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Bundle\TwigBundle\Extension; |
|
13 |
|
14 use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; |
|
15 use Symfony\Component\DependencyInjection\ContainerInterface; |
|
16 |
|
17 /** |
|
18 * Twig extension for Symfony actions helper |
|
19 * |
|
20 * @author Fabien Potencier <fabien@symfony.com> |
|
21 */ |
|
22 class ActionsExtension extends \Twig_Extension |
|
23 { |
|
24 private $container; |
|
25 |
|
26 /** |
|
27 * Constructor. |
|
28 * |
|
29 * @param ContainerInterface $container The service container |
|
30 */ |
|
31 public function __construct(ContainerInterface $container) |
|
32 { |
|
33 $this->container = $container; |
|
34 } |
|
35 |
|
36 /** |
|
37 * Returns the Response content for a given controller or URI. |
|
38 * |
|
39 * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI |
|
40 * @param array $attributes An array of request attributes |
|
41 * @param array $options An array of options |
|
42 * |
|
43 * @see Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver::render() |
|
44 */ |
|
45 public function renderAction($controller, array $attributes = array(), array $options = array()) |
|
46 { |
|
47 return $this->container->get('templating.helper.actions')->render($controller, $attributes, $options); |
|
48 } |
|
49 |
|
50 /** |
|
51 * Returns the token parser instance to add to the existing list. |
|
52 * |
|
53 * @return array An array of Twig_TokenParser instances |
|
54 */ |
|
55 public function getTokenParsers() |
|
56 { |
|
57 return array( |
|
58 // {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %} |
|
59 new RenderTokenParser(), |
|
60 ); |
|
61 } |
|
62 |
|
63 public function getName() |
|
64 { |
|
65 return 'actions'; |
|
66 } |
|
67 } |