Created
October 24, 2011 15:42
-
-
Save hidenorigoto/1309341 to your computer and use it in GitHub Desktop.
Symfony\Bundle\TwigBundle\Extension\ContainerExtension example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of the Symfony package. | |
* | |
* (c) Fabien Potencier <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Symfony\Bundle\TwigBundle\Extension; | |
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
class ContainerExtension extends \Twig_Extension | |
{ | |
private $container; | |
public function __construct(ContainerInterface $container) | |
{ | |
$this->container = $container; | |
} | |
public function getFunctions() | |
{ | |
return array( | |
'container_param' => new \Twig_Function_Method($this, 'getParameter'), | |
); | |
} | |
public function getParameter($key) | |
{ | |
return $this->container->getParameter($key); | |
} | |
public function getName() | |
{ | |
return 'container'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ container_param('kernel.root_dir') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<container xmlns="http://symfony.com/schema/dic/services" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | |
<parameters> | |
: | |
<parameter key="twig.extension.container.class">Symfony\Bundle\TwigBundle\Extension\ContainerExtension</parameter> | |
: | |
</parameters> | |
<services> | |
: | |
<service id="twig.extension.container" class="%twig.extension.container.class%" public="false"> | |
<tag name="twig.extension" /> | |
<argument type="service" id="service_container" /> | |
</service> | |
: | |
</services> | |
</container> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment