CodeIgniter Forums
Problem with Modular Extensions and Template library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem with Modular Extensions and Template library (/showthread.php?tid=53825)



Problem with Modular Extensions and Template library - El Forum - 08-10-2012

[eluser]Rudybg[/eluser]
Hi.
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
Code:
class Home extends MX_Controller {

    function index()
    {
        $this->template->build('login');
    }

}

views\layouts\default.php- the default layout
Code:
<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
Code:
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);
    }
}




Problem with Modular Extensions and Template library - El Forum - 08-10-2012

[eluser]PhilTem[/eluser]
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.


Problem with Modular Extensions and Template library - El Forum - 08-10-2012

[eluser]Rudybg[/eluser]
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;


Problem with Modular Extensions and Template library - El Forum - 08-10-2012

[eluser]Rudybg[/eluser]
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?


Problem with Modular Extensions and Template library - El Forum - 08-10-2012

[eluser]Rudybg[/eluser]
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?