rdrenth/twig-extension-bundle

Symfony bundle with useful twig extensions

1.1.0 2016-07-22 21:13 UTC

This package is not auto-updated.

Last update: 2024-11-20 23:43:43 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight

About

This is a Symfony2 Bundle that provides you with some extensions to Twig!

Twig extensions

Stringy

This extension provides the following filters (provided by the Stringy package).

For more information about each filter, please check the links.

ascii

{{ 'fòôbàř'|ascii }} {# foobar #}

camelize

{{ 'Camel-Case'|camelize }} {# camelCase #}

dasherize

{{ 'fooBar'|dasherize }} {# foo-bar #}

delimit

{{ 'fooBar'|delimit('::') }} {# foo::bar #}

humanize

{{ 'author_id'|humanize }} {# Author #}

slugify

{{ 'Using strings like fòô bàř'| slugify }} {# using-strings-like-foo-bar #}

titleize

{{ 'i like to watch television'|titleize(['to']) }} {# I Like to Watch Television #}

underscored

{{ 'TestUCase'|underscored }} {# test_u_case #}

lcfirst

{{ 'LowerCaseFirst'|lcfirst }} {# lowerCaseFirst #}

ucfirst

{{ 'upperCaseFirst'|ucfirst }} {# UpperCaseFirst #}

Installation

Step 1: Install RdrenthTwigExtensionBundle using Composer

$ composer require rdrenth/twig-extension-bundle

Step 2: Enable the bundle

<?php

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Rdrenth\Bundle\TwigExtensionBundle\RdrenthTwigExtensionBundle(),
        // ...
    );
}

Step 3: Configure your config.yml file

By default the filters are disabled, enable the filters you want to use like this:

# app/config/config.yml
          
rdrenth_twig_extension:
    stringy:
        filters:
            ascii: ~
            camelize: ~

It is also possible to modify the filter name that is being used in Twig:

# app/config/config.yml
          
rdrenth_twig_extension:
    stringy:
        filters:
            camelize:
                filter: camels

Or provide extra filters which are not available by default from the Stringy package (the method has to exist in the Stringy class):

# app/config/config.yml
          
rdrenth_twig_extension:
    stringy:
        extra_filters:
            - { filter: swap_case, method: swapCase }

License

This bundle is under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE