CodeIgniter Forums

Full Version: HMVC and Layout Template Library
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Mark75[/eluser]
Hi,

i'm trying to get Jérôme Jaglales Template Library (http://maestric.com/en/doc/php/codeigniter_template) running along with HMVC.

This is the library:
Code:
class Template {
    var $template_data = array();

    function set($name, $value)
    {
        $this->template_data[$name] = $value;
    }

    function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
    {
        $this->CI =& get_instance();
        $this->set('content', $this->CI->load->view($view, $view_data, TRUE));
        return $this->CI->load->view($template, $this->template_data, $return);
    }

}

and this is a part from my folder structure:
Code:
application
- modules
    -front
      - views
         - partial.php
- views
    - home.php

When i try to load
Code:
$this->template->load('home', 'partial', $this->data);
from my controller, the 'partial'-view is not found, because the library only looks in the global view folder.
How can i make it include the partial view from my module-view folder?

Any help is greatly appreciated.

Cheers,
Mark

El Forum

[eluser]Jérôme Jaglale[/eluser]
In libraries/Template.php add:

Code:
function load_partial($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
    $this->set('contents', $this->template_data['controller']->load->view($view, $view_data, TRUE));
    return $this->template_data['controller']->load->view($template, $this->template_data, $return);
}

In the controller:

Code:
$this->template->set('controller', $this);
$this->template->load_partial('home', 'partial');

Details: if I've understood correctly, HMVC makes the controller use a custom load->view() method, but without overriding load->view() from $this->CI. To make the Template library use the load->view() from HMVC we pass the controller and call load->view() on it.

El Forum

[eluser]Mark75[/eluser]
Hi Jérôme,

thanks for your fast answer. This works perfectly for me!

Regards
Mark

El Forum

[eluser]Flak[/eluser]
Seems logically, but cannot get object, view() is not loaded.

Message: Trying to get property of non-object
Filename: libraries/Template.php
Line Number: 20

Its not getting instance. Call to a member function view() on a non-object on line 20

El Forum

[eluser]Flak[/eluser]
I think I got it.

El Forum

[eluser]kakap[/eluser]
hi,it's very nice library,thanks for it Smile

I wanna aks,
what if I put my template outside CI's system direktori??
how to make it?

my case was:
I've got template from internet,then extract it to folder 'light' under folder 'templates'
my file structure was like this:

|system <folder>
|application <folder>
|templates <folder>
|light <folder>
|images <folder>
|style.css<file>
|header.php <file>
|body.php
|footer.php
|user_guide <folder>

how to use your library to my template?

Help me Please, Thank you Smile

El Forum

[eluser]wiredesignz[/eluser]
[quote author="kakap" date="1247931126"]...how to use your library to my template?[/quote]

Tell the library to use a relative path, such as:

Code:
$this->load->view('../../templates/header', $data);

El Forum

[eluser]kakap[/eluser]
[quote author="wiredesignz" date="1247934809"][quote author="kakap" date="1247931126"]...how to use your library to my template?[/quote]

Tell the library to use a relative path, such as:

Code:
$this->load->view('../../templates/header', $data);
[/quote]

thank you Smile

but,I mean how to use this template library http://maestric.com/wiki/lib/exe/fetch.p...brary3.zip) where my template folder is in outside of system directory ?Smile

"How you usually load a view:

$this->load->view('about', $data);

How you load a view into a template with this library:

$this->template->load('template', 'about', $data);

That loads the view about.php into template.php."
that's I take example from the site http://maestric.com/doc/php/codeigniter_template

Any body, I expect your help,Tq Smile

El Forum

[eluser]tahsin352[/eluser]
Hello,

Here comes a new layout library with new features for using any number of html blocks in the layout. check it out <a href="http://newdailyblog.blogspot.com/2010/07/codeigniter-advanced-layout-library.html">http://newdailyblog.blogspot.com/2010/07/codeigniter-advanced-layout-library.html</a>. You can also use it in hmvc modular form.

El Forum

[eluser]TomTom[/eluser]
[quote author="Jérôme Jaglale" date="1246405206"]In libraries/Template.php add:

Code:
function load_partial($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
    $this->set('contents', $this->template_data['controller']->load->view($view, $view_data, TRUE));
    return $this->template_data['controller']->load->view($template, $this->template_data, $return);
}

In the controller:

Code:
$this->template->set('controller', $this);
$this->template->load_partial('home', 'partial');
[/quote]

This isn't working for me. My folders' structure is this:

Code:
root
- application
  - modules
    - blog
      - controllers
        - blog.php
      - views
        - blog.php
    - frontend
      - controllers
        - frontend.php
      - views
        - footer.php
        - header.php
        - main.php
        - sidebar.php
    - menu
      - controllers
        - menu.php
      - views
        - menu.php

I've added the required code to Template.php and this code to index method in my frontend.php:

Code:
$this->template->set('controller', $this);
$this->template->load_partial('main', 'menu');

When I load the Frontend's index method, I get the error message:

Quote:Unable to load the requested file: menu.php