Skip to content

Instantly share code, notes, and snippets.

@erikaheidi
Last active December 15, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikaheidi/5203854 to your computer and use it in GitHub Desktop.
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.
<?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