Added |yaml filter to convert input to YAML

This commit is contained in:
Matias Griese
2021-09-02 20:02:07 +03:00
parent aedf8cda47
commit 907e46631c
2 changed files with 15 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
# v1.7.21
## mm/dd/2021
1. [](#bugfix)
1. [](#new)
* Added `|yaml` filter to convert input to YAML
3. [](#bugfix)
* Fixed escaping in PageIndex::getLevelListing()
* Fixed validation of `number` type [#3433](https://github.com/getgrav/grav/issues/3433)

View File

@@ -155,6 +155,7 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
new TwigFilter('bool', [$this, 'boolFilter']),
new TwigFilter('float', [$this, 'floatFilter'], ['is_safe' => ['all']]),
new TwigFilter('array', [$this, 'arrayFilter']),
new TwigFilter('yaml', [$this, 'yamlFilter']),
// Object Types
new TwigFilter('get_type', [$this, 'getTypeFunc']),
@@ -807,6 +808,17 @@ class GravExtension extends AbstractExtension implements GlobalsInterface
return (array)$input;
}
/**
* @param array|object $value
* @param int|null $inline
* @param int|null $indent
* @return string
*/
public function yamlFilter($value, $inline = null, $indent = null): string
{
return Yaml::dump($value, $inline, $indent);
}
/**
* @param Environment $twig
* @return string