mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 04:17:09 +02:00
Added a few filters
This commit is contained in:
@@ -60,9 +60,9 @@ form:
|
||||
label: PLUGIN_ADMIN.SUMMARY_SIZE
|
||||
help: PLUGIN_ADMIN.SUMMARY_SIZE_HELP
|
||||
validate:
|
||||
type: int
|
||||
min: 0
|
||||
max: 65536
|
||||
type: int
|
||||
min: 0
|
||||
max: 65536
|
||||
|
||||
summary.format:
|
||||
type: toggle
|
||||
|
||||
@@ -55,9 +55,12 @@ class TwigExtension extends \Twig_Extension
|
||||
new \Twig_SimpleFilter('ksort', [$this,'ksortFilter']),
|
||||
new \Twig_SimpleFilter('contains', [$this, 'containsFilter']),
|
||||
new \Twig_SimpleFilter('nicetime', [$this, 'nicetimeFilter']),
|
||||
new \Twig_SimpleFilter('defined', [$this, 'definedDefaultFilter']),
|
||||
new \Twig_SimpleFilter('absolute_url', [$this, 'absoluteUrlFilter']),
|
||||
new \Twig_SimpleFilter('markdown', [$this, 'markdownFilter']),
|
||||
new \Twig_SimpleFilter('starts_with', [$this, 'startsWithFilter']),
|
||||
new \Twig_SimpleFilter('rtrim', [$this, 'rtrimFilter']),
|
||||
new \Twig_SimpleFilter('ltrim', [$this, 'ltrimFilter']),
|
||||
new \Twig_SimpleFilter('ends_with', [$this, 'endsWithFilter']),
|
||||
new \Twig_SimpleFilter('t', [$this, 'translate']),
|
||||
new \Twig_SimpleFilter('ta', [$this, 'translateArray'])
|
||||
@@ -370,6 +373,25 @@ class TwigExtension extends \Twig_Extension
|
||||
return Utils::endsWith($haystack, $needle);
|
||||
}
|
||||
|
||||
public function definedDefaultFilter($value, $default)
|
||||
{
|
||||
if (isset($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
public function rtrimFilter($value, $chars = null)
|
||||
{
|
||||
return rtrim($value, $chars);
|
||||
}
|
||||
|
||||
public function ltrimFilter($value, $chars = null)
|
||||
{
|
||||
return ltrim($value, $chars);
|
||||
}
|
||||
|
||||
public function translate()
|
||||
{
|
||||
return $this->grav['language']->translate(func_get_args());
|
||||
@@ -381,6 +403,8 @@ class TwigExtension extends \Twig_Extension
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Repeat given string x times.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user