Last active
December 15, 2015 04:49
-
-
Save erikaheidi/5203854 to your computer and use it in GitHub Desktop.
a truncate filter for Twig. Just add this after registering the Twig Service Provider.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$app['twig']->addFilter(new Twig_SimpleFilter('truncate', function($string, $size) { | |
if(strlen($string) < $size) | |
return $string; | |
else | |
return array_shift(str_split($string, $size)) . "..."; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment