crowdcube/twig-extensions

This package is abandoned and no longer maintained. No replacement package was suggested.

Collection of useful Twig extensions

0.2.0 2016-05-12 15:44 UTC

README

Circle CI

Provides a collection of helpful Twig extensions.

Installation

Add crowdcube\twig-extensions as a requirement to composer.json:

{
    "require": {
        "crowdcube\twig-extensions": "~0.1"
    }
}

Usage

Add the relevant extension to Twig:

$twig->addExtension(new Crowdcube\Twig\Extensions\Thumbor(...));

Extensions

Markdown

Refer to /aptoma/twig-markdown documentation

To change markdown engine, pass in as a dependency:

new Aptoma\Twig\Extension\MarkdownExtension(new Aptoma\Twig\Extension\MarkdownEngine\PHPLeagueCommonMarkEngine()),

Provides:

{{ content | markdown }}

or:

{% markdown %}
# Title here
some content...
{% endmarkdown %}

Currency

Crowdcube\Twig\Extensions\Currency

Provide: {{ currency | currency_symbol }} - Given a currency, ie GBP, will return the Symbol = £

Array filter

Crowdcube\Twig\Extensions\ArrayFilter

Provides: {{ [1,2,null,3] | array_filter }} - Removes empty values from an array (proxies array_filter).

Number

Crowdcube\Twig\Extensions\Number

Provides: {{ number | number_abbreviate }} - Abbreviates a given number, e.g. 1,500,000 = 1.5m.

Slugify

Refer to cocur/slugify documentation.

Thumbor: Crowdcube\Twig\Extensions\Thumbor

Twig extension for \Thumbor\Url\BuilderFactor.

Provides: {{ thumbor() }} - Returns a thumbor builder instance so you can chain. {{ thubor(url).fitIn(200, 200) }}.