added twig filters for starts_with and ends_with

This commit is contained in:
Andy Miller
2015-05-07 14:13:05 -06:00
parent b2a78d587c
commit 14767a3e11

View File

@@ -52,7 +52,9 @@ class TwigExtension extends \Twig_Extension
new \Twig_SimpleFilter('contains', [$this, 'containsFilter']),
new \Twig_SimpleFilter('nicetime', [$this, 'nicetimeFilter']),
new \Twig_SimpleFilter('absolute_url', [$this, 'absoluteUrlFilter']),
new \Twig_SimpleFilter('markdown', [$this, 'markdownFilter'])
new \Twig_SimpleFilter('markdown', [$this, 'markdownFilter']),
new \Twig_SimpleFilter('starts_with', [$this, 'startsWithFilter']),
new \Twig_SimpleFilter('ends_with', [$this, 'endsWithFilter'])
];
}
@@ -347,6 +349,16 @@ class TwigExtension extends \Twig_Extension
return $string;
}
public function startsWithFilter($needle, $haystack)
{
return Utils::startsWith($needle, $haystack);
}
public function endsWithFilter($needle, $haystack)
{
return Utils::endsWith($needle, $haystack);
}
/**
* Repeat given string x times.
*