2017 © Pedro Peláez
 

library twig-truncate-extension

Twig Extension to truncate nested HTML, safely!

image

bluetel-solutions/twig-truncate-extension

Twig Extension to truncate nested HTML, safely!

  • Monday, January 18, 2016
  • by antoligy
  • Repository
  • 5 Watchers
  • 6 Stars
  • 3,063 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 5 Versions
  • 55 % Grown

The README.md

Twig Truncation Extension

Build Status, (*1)

This extension attempts to solve a common problem, namely that of truncating HTML content based on the number of characters and on the number of words contained., (*2)

Other libraries we have tried attempt to manipulate the HTML content by means of regular expressions which is liable to break, and always seems to at the worst times, hence the need for this extension. This leverages the power of DOMDocument to safely truncate even the most complex of nested HTML documents., (*3)

Truncating on word count

{% set html %}
    <h1>Test heading!</h1>
    <ul>
        <li>Hello world</li>
        <li>Foo bar</li>
        <li>Lorem Ipsum</li>
    </ul>
{% endset html %}
{{ html|truncate_words(5) }}

Running this returns:, (*4)

<h1>Test heading!</h1>
<ul>
    <li>Hello world</li>
    <li>Foo</li>
</ul>

Truncating on character count

{% set html %}
    <h1>Test heading!</h1>
    <ul>
        <li>Hello world</li>
        <li>Foo bar</li>
        <li>Lorem Ipsum</li>
    </ul>
{% endset html %}
{{ html|truncate_letters(20) }}

Whereas running the above returns the following:, (*5)

<h1>Test heading!</h1>
<ul>
    <li>Hello wo</li>
</ul>

The Versions

18/01 2016

dev-master

9999999-dev

Twig Extension to truncate nested HTML, safely!

  Sources   Download

MIT

The Requires

 

twig twig extension truncate

18/01 2016

v0.1.3

0.1.3.0

Twig Extension to truncate nested HTML, safely!

  Sources   Download

MIT

The Requires

 

twig twig extension truncate

15/12 2015

v0.1.2

0.1.2.0

Twig Extension to truncate nested HTML, safely!

  Sources   Download

MIT

The Requires

 

twig twig extension truncate

15/12 2015

v0.1.1

0.1.1.0

Twig Extension to truncate nested HTML, safely!

  Sources   Download

MIT

The Requires

 

twig twig extension truncate

05/11 2015

v0.1.0

0.1.0.0

Twig Extension to truncate nested HTML, safely!

  Sources   Download

MIT

The Requires

 

twig twig extension truncate