[TwigBundle] added a yaml filter
This commit is contained in:
parent
e0d6aad5f4
commit
17c500e0f0
@ -7,6 +7,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\IncludeTokenParser;
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\UrlTokenParser;
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\PathTokenParser;
|
||||
use Symfony\Component\Yaml\Dumper as YamlDumper;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
@ -42,6 +43,16 @@ class TemplatingExtension extends \Twig_Extension
|
||||
return $this->templating;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
'yaml' => new \Twig_Filter_Method($this, 'yaml'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the token parser instance to add to the existing list.
|
||||
*
|
||||
@ -82,6 +93,17 @@ class TemplatingExtension extends \Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
public function yaml($input, $inline = 0)
|
||||
{
|
||||
static $dumper;
|
||||
|
||||
if (null === $dumper) {
|
||||
$dumper = new YamlDumper();
|
||||
}
|
||||
|
||||
return $dumper->dump($input, $inline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
|
Reference in New Issue
Block a user