* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * * @author Fabien Potencier */ class TemplatingExtension extends \Twig_Extension { protected $container; public function __construct(ContainerInterface $container) { $this->container = $container; } public function getContainer() { return $this->container; } public function getTemplating() { return $this->container->get('templating.engine'); } /** * {@inheritdoc} */ public function getFilters() { return array( 'yaml_encode' => new \Twig_Filter_Method($this, 'yamlEncode'), 'dump' => new \Twig_Filter_Method($this, 'dump'), 'abbr_class' => new \Twig_Filter_Method($this, 'abbrClass', array('is_safe' => array('html'))), 'abbr_method' => new \Twig_Filter_Method($this, 'abbrMethod', array('is_safe' => array('html'))), 'format_args' => new \Twig_Filter_Method($this, 'formatArgs', array('is_safe' => array('html'))), 'format_args_as_text' => new \Twig_Filter_Method($this, 'formatArgsAsText', array('is_safe' => array('html'))), 'file_excerpt' => new \Twig_Filter_Method($this, 'fileExcerpt', array('is_safe' => array('html'))), 'format_file' => new \Twig_Filter_Method($this, 'formatFile', array('is_safe' => array('html'))), 'format_file_from_text' => new \Twig_Filter_Method($this, 'formatFileFromText', array('is_safe' => array('html'))), ); } /** * Returns the token parser instance to add to the existing list. * * @return array An array of Twig_TokenParser instances */ public function getTokenParsers() { return array( // {% javascript 'bundles/blog/js/blog.js' %} new HelperTokenParser('javascript', ' [with ]', 'templating.helper.javascripts', 'add'), // {% javascripts %} new HelperTokenParser('javascripts', '', 'templating.helper.javascripts', 'render'), // {% stylesheet 'bundles/blog/css/blog.css' with ['media': 'screen'] %} new HelperTokenParser('stylesheet', ' [with ]', 'templating.helper.stylesheets', 'add'), // {% stylesheets %} new HelperTokenParser('stylesheets', '', 'templating.helper.stylesheets', 'render'), // {% asset 'css/blog.css' %} new HelperTokenParser('asset', '', 'templating.helper.assets', 'getUrl'), // {% render 'BlogBundle:Post:list' with ['limit': 2], ['alt': 'BlogBundle:Post:error'] %} new HelperTokenParser('render', '