saxulum/saxulum-assetic-twig-provider

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

Saxulum Assetic Twig Provider

2.0.5 2015-12-01 11:51 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+
  • Symfony Finder Component 2.3+
  • Twig 1.2+

Installation

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

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

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

        return $twigLoaderFilesystem;
    }
));

$app->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:

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

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

$container['assetic.filterinstances'] = $container->share(
    $app->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