如何使用Twig命名空间定义的资源使Assetic工作?

时间:2015-09-03 16:00:49

标签: php twig silex assetic

我正在尝试完成简单的任务:使用Silex处理树枝模板中的资产块。我刚刚注册了TwigServiceProviderAsseticServiceProvider

所有资产块都由twig解析器识别,但没有使用命名空间表示法定义的资产(如“@ App / image.jpg”)添加到资产管理器中。当Assetic尝试解析我的资产时,它会生成所有路径但无法从Asset Manager加载资产。

我的问题:资产何时加载到Assets Manager对象中?我需要做什么才能使我的应用程序在处理树枝模板时自动转储并加载所有资产。

的index.php

$app->register(new Silex\Provider\TwigServiceProvider());

$app->register(new SilexAssetic\AsseticServiceProvider());

$app['assetic.path_to_web'] = __DIR__ . '/assets';
$app['assetic.options'] = array(
    'auto_dump_assets' => true,
    'debug' => true,
);

$app['twig.loader.filesystem']->addPath(__DIR__.'/views', 'App');

if ($app['assetic.options']['auto_dump_assets']){
    $dumper = $app['assetic.dumper'];
    if (isset($app['twig'])) {
        $dumper->addTwigAssets();
    }
    $dumper->dumpAssets();
}

$app->get('/', function(Silex\Application $app) {
    return $app['twig']->render('@App/index.html.twig');
});

index.html.twig

{% image '@App/demo.jpg'  %}
<img src="{{ asset_url }}" class="img-responsive"  alt="">
{% endimage %}

问题出在 @ 符号中。当我删除它,一切正常。但是Assetic知道如何处理命名空间。我希望它能够使用名称空间,因为这些模板也将被Symfony应用程序使用,现在所有这些模板都能正常运行 @ 符号。

0 个答案:

没有答案