Skip to content

rdrenth/twig-extension-bundle

Repository files navigation

RdrenthTwigExtensionBundle

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.

{{ 'fòôbàř'|ascii }} {# foobar #}
{{ 'Camel-Case'|camelize }} {# camelCase #}
{{ 'fooBar'|dasherize }} {# foo-bar #}
{{ 'fooBar'|delimit('::') }} {# foo::bar #}
{{ 'author_id'|humanize }} {# Author #}
{{ 'Using strings like fòô bàř'| slugify }} {# using-strings-like-foo-bar #}
{{ 'i like to watch television'|titleize(['to']) }} {# I Like to Watch Television #}
{{ 'TestUCase'|underscored }} {# test_u_case #}
{{ 'LowerCaseFirst'|lcfirst }} {# lowerCaseFirst #}
{{ '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

About

A Symfony Bundle that provides some extensions to Twig!

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages