Twig_Environment::addFilter PHP Method

addFilter() public method

public addFilter ( $name, Twig_FilterInterface $filter )
$filter Twig_FilterInterface
    public function addFilter($name, Twig_FilterInterface $filter)
    {
        if (null === $this->filters) {
            $this->getFilters();
        }

        $this->filters[$name] = $filter;
    }

Same methods

Twig_Environment::addFilter ( string $name, Twig_FilterInterface $filter )

Usage Example

 private function maybe_init_twig()
 {
     if (!isset($this->twig)) {
         $loader = new Twig_Loader_Filesystem($this->template_paths);
         $environment_args = array();
         if (WP_DEBUG) {
             $environment_args['debug'] = true;
         }
         $wpml_cache_directory = new WPML_Cache_Directory(new WPML_WP_API());
         $cache_directory = $wpml_cache_directory->get('twig');
         if ($cache_directory) {
             $environment_args['cache'] = $cache_directory;
             $environment_args['auto_reload'] = true;
         }
         $this->twig = new Twig_Environment($loader, $environment_args);
         if (isset($this->custom_functions) && count($this->custom_functions) > 0) {
             foreach ($this->custom_functions as $custom_function) {
                 $this->twig->addFunction($custom_function);
             }
         }
         if (isset($this->custom_filters) && count($this->custom_filters) > 0) {
             foreach ($this->custom_filters as $custom_filter) {
                 $this->twig->addFilter($custom_filter);
             }
         }
     }
 }
All Usage Examples Of Twig_Environment::addFilter