saxulum/saxulum-assetic-twig-provider

Saxulum Assetic Twig Provider

Installs: 850

Dependents: 2

Stars: 4

Watchers: 1

Forks: 1

Language: PHP

2.0.1 2015-01-28 21:37 UTC

README

works with plain silex-php

Build Status Total Downloads Latest Stable Version

Features

  • Add assetic support for twig templates

Requirements

  • PHP 5.3+
  • Kriswallsmith's Assets Framework (Assetic) 1.2+
  • Pimple >=2.1,<4
  • Symfony Finder Component 2.3+
  • Twig 1.2+

Installation

Through Composer as saxulum/saxulum/saxulum-assetic-twig-provider.

$container->register(new TwigServiceProvider());

$container['twig.loader.filesystem'] = $container->extend('twig.loader.filesystem',
    function (\Twig_Loader_Filesystem $twigLoaderFilesystem) {
        $twigLoaderFilesystem->addPath('/path/to/the/views', 'SomeNamespace');

        return $twigLoaderFilesystem;
    }
);

$container->register(new AsseticTwigProvider(), array(
    'assetic.asset.root' => '/path/to/project/root',
    'assetic.asset.asset_root' => '/path/to/asset/root',
));

Configuration

This filter are preconfigured, and active per default:

  • csscopyfile
  • lessphp
  • scssphp
  • cssmin
  • csscompress
  • jsmin

If you want to disable a default filter:

$container['assetic.filters'] = $container->extend('assetic.filters',
    function ($filters) use ($container) {
        $filters['cssmin'] = false;
        return $filters;
    }
);

If you want to add more filters, which aren't preconfigured:

$container['assetic.filterinstances'] = $container->extend('assetic.filterinstances',
    function ($filterInstances) use ($container) {
        $filterInstances['jsminplus'] = new JSMinPlusFilter();

        return $filterInstances;
    }
);

Usage

CSS example

{% stylesheets
    'relative/from/path/to/project/root/*.css'
    output='relative/from/path/to/asset/root/css/test.css'
    filter='cssmin'
%}
    {{ asset_url }}
{% endstylesheets %}

JS example

{% javascripts
    'relative/from/path/to/project/root/*.js'
    output='relative/from/path/to/asset/root/css/test.js'
    filter='jsmin'
%}
    {{ asset_url }}
{% endjavascripts %}

Copyright