How do I fix "Add myBundle to the asseticBundle config" symfony2 exception?

PhpSymfonyTwig

Php Problem Overview


When I am trying to use the TWIG {% javascript %} tag to link to my .js file it return me with the following exception :

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".

My index.html.twig looks like :

{% javascripts 'CompetitiongameBundle/Resources/views/public/js/*'%}
	<script type="text/javascript" src="{{ asset_url }}" ></script>
{% endjavascripts %}
Hello {{ name }}!

<a href='{{ nexturl }}' >Login</a>

My Bundle is already present in the config file when I do :

php app/console config:dump-reference assetic

How can I fix this ?

Php Solutions


Solution 1 - Php

Yes I tried and it solved the issue for me. For someone (like me) who doesn't know initially how to add then just:

  1. edit app/config/config.yml
  2. then go to assetic:
  3. under assetic: go to bundles: []
  4. and in bundles: [] //type your bundle name

for instance if your bundle is Acme\DemoBundle, then do the following

assetic:
   bundles: [ AcmeDemoBundle ]

No quotes around AcmeDemoBundle. That's it. (Symfony2)

Solution 2 - Php

If you want assetic to include your bundles by default, you can comment (with #) the line bundles: []

ex:

assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    #bundles:        [ ]
    #java: /usr/bin/java

Solution 3 - Php

Sometimes you need to make decisions on the fly, then you can use use DependencyInjection.

For example to loads and manages configuration:

<?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);

        /* ... */
    }
}

You can use more complex logic to manipulate the configuration(in reasonable limits)

Solution 4 - Php

You need to add your bundle to bundle: [] row of assetic: section in app/config/config.yml file (symfony 2.1)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionManish BasdeoView Question on Stackoverflow
Solution 1 - PhpShabbir ReshamwalaView Answer on Stackoverflow
Solution 2 - PhpTivieView Answer on Stackoverflow
Solution 3 - PhpМаксим ШатовView Answer on Stackoverflow
Solution 4 - Phpuser1041503View Answer on Stackoverflow