You can create a simple branch extension that handled this.
Twig file ..
namespace Acme\SomeBundle\Twig; class DevExtension extends \Twig_Extension { public function getFunctions() { return array( new \Twig_SimpleFunction('die', 'die'), ); } public function getName() { return 'acme_dev'; } }
Your Services File (YAML) ..
services: acme.twig.dev_extension: class: Acme\SomeBundle\Twig\DevExtension tags: - { name: twig.extension }
Additionally, you can go to the current environment, and then either die or fail in silence, depending on the environment, if for some reason you left a stamp in your code.
Extension of your branch ..
class DevExtension extends \Twig_Extension { private $environment; public function __construct($environment) { $this->environment = $environment; } public function getFunctions() { return array( new \Twig_SimpleFunction('die', array($this,'killRender')), ); } public function killRender($message = null) { if ('dev' === $this->environment) { die($message); } return ''; } ... }
Your services file ..
services: acme.twig.dev_extension: class: Acme\SomeBundle\Twig\DevExtension arguments: - %kernel.environment% tags: - { name: twig.extension }
source share