当我尝试使用TWIG {% javascript %}
标记链接到我的.js
文件时,它会返回以下异常:
An exception has been thrown during the compilation of a template ("You must add CompetitiongameBundle to the assetic.bundle config to use the {% javascripts %} tag in CompetitiongameBundle:game:index.html.twig.") in "CompetitiongameBundle:game:index.html.twig".
Run Code Online (Sandbox Code Playgroud)
我index.html.twig
看起来像:
{% javascripts 'CompetitiongameBundle/Resources/views/public/js/*'%}
<script type="text/javascript" src="{{ asset_url }}" ></script>
{% endjavascripts %}
Hello {{ name }}!
<a href='{{ nexturl }}' >Login</a>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我的Bundle已经存在于配置文件中:
php app/console config:dump-reference assetic
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题 ?
小智 175
是的,我试过,它解决了我的问题.对于那些最初不知道如何添加的人(比如我)而言:
app/config/config.yml
assetic:
bundles: []
bundles: []
//键入您的包名称例如,如果您的捆绑包是Acme\DemoBundle
,请执行以下操作
assetic:
bundles: [ AcmeDemoBundle ]
Run Code Online (Sandbox Code Playgroud)
周围没有报价AcmeDemoBundle
.而已.(Symfony2的)
Tiv*_*vie 24
如果您希望assetic默认包含您的软件包,您可以对该行进行注释(使用#) bundles: []
例如:
assetic:
debug: "%kernel.debug%"
use_controller: false
#bundles: [ ]
#java: /usr/bin/java
Run Code Online (Sandbox Code Playgroud)
Мак*_*тов 10
有时你需要动态做出决定,然后你可以使用DependencyInjection.
例如,加载和管理配置:
<?php
namespace You\ExampeBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/* ... */
class YouExampeExtension extends Extension
{
/* ... */
public function load(array $configs, ContainerBuilder $container)
{
/* ... */
$aAsseticBundle = $container->getParameter('assetic.bundles');
$aAsseticBundle[] = 'YouExampeBundle';
$aAsseticBundle[] = 'AnotheBundle';
$container->setParameter('assetic.bundles', $aAsseticBundle);
/* ... */
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用更复杂的逻辑来操作配置(在合理的限制范围内)
归档时间: |
|
查看次数: |
36249 次 |
最近记录: |