Set a breakpoint in Twig templates and debug some or all variables ( equivalent to {{ dump() }} )
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
services: | |
twig_extension.inspect: | |
class: Acme\HelloBundle\Extensions\InspectExtension | |
tags: | |
- { name: twig.extension } |
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 | |
namespace Acme\HelloBundle\Extensions; | |
/** | |
* Inspect Twig templates with a debugger. | |
* Usages: | |
* {{ inspect() }} | |
* {{ inspect(myVar) }} | |
*/ | |
class InspectExtension extends \Twig_Extension | |
{ | |
/** | |
* @return array | |
*/ | |
public function getFunctions() | |
{ | |
return array( | |
'inspect' => new \Twig_Function_Method($this, 'inspect', array('needs_context' => true)) | |
); | |
} | |
/** | |
* @param $context | |
*/ | |
public function inspect($context) | |
{ | |
$this->breakPoint(1 === func_num_args() ? $context : func_get_arg(1)); | |
} | |
/** | |
* This where you set your breakpoint | |
*/ | |
protected function breakPoint($twig) | |
{ | |
return; // breakpoint | |
} | |
/** | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return 'inspect'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment