Skip to content

Instantly share code, notes, and snippets.

View m-radzikowski's full-sized avatar

Maciej Radzikowski m-radzikowski

View GitHub Profile
@m-radzikowski
m-radzikowski / TruncateHtmlExtension.php
Created July 2, 2013 19:13
Twig Filter for Symfony 2 - truncate HTML string without stripping tags after reach the minimum length of displayed text
<?php
/**
* Twig Filter for Symfony 2 - truncate HTML string without stripping tags after reach the minimum length of displayed text
* Truncates only first-level tags after reach the minimum, so returned text will be >= minimum
* Works well with (only?) utf-8 encoding.
*
* Installation:
* 1. Add this file to your bundle into src/Acme/DemoBundle/Twig/TruncateHtmlExtension.php
* 2. Update namespace, if your bundle isn't Acme/DemoBundle
* 3. Register it in app/config.yml: