0

I use Modular Extensions HMVC and Template library by Phil Sturgeon. How can I use $this->template in a module's controller. I want to load some module's javascript files in the head of the html layout with the append_metadata() method.

An example in order of execution:

controllers/home/home.php - the main controller

class Home extends MX_Controller {
    function index()
    {
    $this->template->build('login');
    }
}

views\layouts\default.php- the default layout

 <html>
  <head>
    <?php include "\..\partials\head.php"; ?>
  </head>
  <body>
       //calling topbar module
    <?php echo Modules::run('navigation_panels/TopBar/render'); ?>
    <?php echo $template['body']; ?>
  </body>
   </html>  

modules\navigation_panels\controllers\TopBar.php- the topbar module's controller

class TopBar extends MX_Controller {

public function __construct()
{
    parent::__construct();
//want to manipulate the head but template property is not visible 
      $this->template
 ->prepend_metadata(generateJavaScriptIncludeTag('TOPBAR_JAVASCRIPT_LOCATION' .        'change_language.js'));
}

public function render()
{
    $data['languages'] = $this->language->getOtherLanguageArray();
    $this->load->view('TopBar_view', $data);
}
}

It seems to be output buffering problem, because the method prepend_metadata() exists.

1 Answers1

0

If i'm not wrong the append_metadata methos has been replaced by appens_js in the last version of the library that is also used in PyroCMS.

To use it you need:

$this->template
              ->appens_js('your file_name here')
              ->build('your view here');

If append_js doen't work just replace it with append_metadata

Christian Giupponi
  • 7,408
  • 11
  • 68
  • 113
  • No, the method append_js() doesn't exist in the library. append_metadata() is working in other files, but the problem here is the scope - $this->template is not visible in this context.. – Radoslav Gatev Aug 10 '12 at 15:45