Search code examples
phpconcrete5concrete5-5.7concrete

Concrete5 import JS or CSS in single page


I've been checking this page out on their docs: http://documentation.concrete5.org/developers/assets/requiring-an-asset

But none of the options are working out for me. No errors or anything. It just ignores the requireAsset method.

Controller:

<?php
namespace Application\Controller\SinglePage;

use PageController;

class MyAccount extends PageController
{
  public function view()
  {
    $this->requireAsset('javascript', 'js/my_account');
  }
}

Solution

  • Managed to finally find how to do it properly, after much digging. Here's how...

    application/config/app.php:

    <?php
    
    return array(
        'assets' => array(
    
          'foobar/my-account' => array(
                array(
                    'javascript',
                    'js/my_account.js'
                ),
            ),
    
        ),
    );
    

    Controller:

    <?php
    namespace Application\Controller\SinglePage;
    
    use PageController;
    
    class MyAccount extends PageController
    {
      public function view()
      {
        $this->requireAsset('javascript', 'foobar/my-account');
      }
    }