works with plain silex-php
- Add assetic support for twig templates
- PHP 5.3+
- Kriswallsmith's Assets Framework (Assetic) 1.2+
- Symfony Finder Component 2.3+
- Twig 1.2+
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',
));
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;
})
);
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 %}
- Dominik Zogg dominik.zogg@gmail.com