[TwigBundle] added a yaml filter

This commit is contained in:
Fabien Potencier 2010-11-19 09:50:32 +01:00
parent e0d6aad5f4
commit 17c500e0f0

View File

@ -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.
*