• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Modular Extensions and Template library

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()


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

modules\navigation_panels\controllers\TopBar.php- the topbar module's controller
class TopBar extends MX_Controller {

    public function __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);

Just don't put it in the __construct() but in the method called - in your case the 'render'-method. I think that should be it.

Isn't working. It only works when i call prepend_metadata() just before the build() method. By the way i checked with method_exists($this->template,'prepend_metadata') -> returns TRUE. But when i call it - no results;

Did i understand the HMVC conception. My idea is to use the application/controllers to reach the website from url and these controllers to load layouts, use modules and to append the modules to the layouts. The module views will be only parts - example container with main menu, top bar, profile. Is that right?

OK. The problem is that I use two different successors of MX_Controller and they have two different instances of template in $this->template. What should I do?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.