saxulum/saxulum-assetic-twig-provider

此软件包已被 弃用 并不再维护。没有建议的替代软件包。

Saxulum Assetic Twig Provider

2.0.5 2015-12-01 11:51 UTC

README

与 plain silex-php 兼容

Build Status Total Downloads Latest Stable Version

特性

  • 为 Twig 模板添加 Assetic 支持

要求

  • PHP 5.3+
  • Kriswallsmith 的 Assets 框架 (Assetic) 1.2+
  • Symfony Finder 组件 2.3+
  • Twig 1.2+

安装

通过 Composer 作为 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',
));

配置

此过滤器已预配置,默认启用

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

如果您想禁用默认的过滤器

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

如果您想添加更多未预配置的过滤器

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

        return $filterInstances;
    })
);

用法

CSS 示例

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

JS 示例

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

版权