I have searched for a couple hours for help on this. No luck.

Following the docs here.

My first two passes were unsuccessful so I deleted everything and started over.

1) I created a plugin scaffolding with a single controller and successfully registered that plugin. I did not edit anything in that plugin.

2) I created the file "FooBundle.php" in the following folder structure:


3) I edited the contents of FooBundle.php to be exactly the docs:

namespace ns\prefix;

use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

class MyPluginAsset extends AssetBundle
    public function init()
        // define the path that your publishable resources live
        $this->sourcePath = '@ns/prefix/resources';

        // define the dependencies
        $this->depends = [

        // define the relative path to CSS/JS files that should be registered with the page
        // when this asset bundle is registered
        $this->js = [

        $this->css = [


Lastly I added the following line after my {% extends "base.html" %} in my index.html. My first two lines of index.html look like this:

{% extends "base.html" %}
{% do view.registerAssetBundle("ns\\prefix\\FooBundle") %}

When I refresh my site index page I get:


Class ns\prefix\FooBundle does not exist

  • How about making it class FooBundle extends AssetBundle
    – kr37
    May 6, 2018 at 1:37
  • I get the same error. May 6, 2018 at 13:48

1 Answer 1


Because your FooBundle has the classname MyPluginAssetrename your class to FooBundle and it should work (if your namespace is correct, since your information are not really detailed as always)

The docs are not supposed to be a place for copy paste but a source for information.

  • OK. So it is a namespace/classname error. Thanks for the pointer in the right direction. Namespaces are new to me. My last PHP work was in 4.x. May 6, 2018 at 14:06
  • "The docs are not supposed to be a place for copy paste but a source for information.". Yep, I understand. I am still learning/rebuilding my knowledge after being out of PHP a long time. I'm really sorry for my lack of knowledge. I appreciate your patience and willingness to share and help. May 6, 2018 at 14:06
  • It's not your fault. Craft docs are not that good. Some things are well explained there (that's why I always refer to those) and many questions here can be solved by looking in the documentation but for most things it's better/easier to look at yii2 instead of Craft May 6, 2018 at 19:28
  • I had the same problem, but I corrected the namespace, the name of the file I had changed already. But I am still facing the same error. :(
    – Rohan
    Jun 5, 2020 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.