diff options
author | Fabian Becker <halfdan@xnorfz.de> | 2013-04-07 02:44:39 +0400 |
---|---|---|
committer | Fabian Becker <halfdan@xnorfz.de> | 2013-04-07 02:44:39 +0400 |
commit | 7eb3401e64c12259b48d9da2ded908d4b7a56d14 (patch) | |
tree | 6b126742f9a13724eadd5e335c9c8cff7f4acf66 /core/Twig.php | |
parent | 91ce0bb684a742dd896ff8299e94c09617daa309 (diff) |
New truncate filter (port of smarty feature)
Diffstat (limited to 'core/Twig.php')
-rw-r--r-- | core/Twig.php | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/core/Twig.php b/core/Twig.php index 120e788ce2..016ff053de 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -179,6 +179,15 @@ class Piwik_Twig return Piwik::getPrettyMoney($amount, $idSite); }); $this->twig->addFilter($moneyFilter); + + $truncateFilter = new Twig_SimpleFilter('truncate', function($string, $size) { + if(strlen($string) < $size) { + return $string; + } else { + return array_shift(str_split($string, $size)) . "..."; + } + }); + $this->twig->addFilter($truncateFilter); } private function addPluginNamespaces(Twig_Loader_Filesystem $loader) |