Search code examples
assetsbowerpyrocms

PyroCMS assets plugin with bower_components


I want to manage my theme assets using bower.

How would I configure PyroCMS / the assets plugin to get may assets from the bower_components folder?


Solution

  • Only for 2.1 or 2.2 version.

    In your controller or base controller (maybe system/cms/core/public_controller.php) constructor, register the path for bower_components writing the next code:

     // Set the theme bower components as a path for Asset library
     Asset::add_path('bower', array(
         'path' => $this->theme->path.'/bower_components',
         'js_dir' => '/',
         'css_dir' => '/',
     ));
    

    Use this in your views writing first the name of path:

    {{ asset:js file="bower::jquery/dist/jquery.js" }} // For JS
    {{ asset:css file="bower::bootstrap/dist/css/bootstrap.css" }} // For CSS
    

    For correct read of assets you must place the bower.json and bower_components folder to your theme folder, for example:

    addons/shared_addons/themes/your_theme/bower.json
    addons/shared_addons/themes/your_theme/bower_components/