EllisLab text mark
Advanced Search
     
HMVC and Layout Template Library
Posted: 29 June 2009 08:37 AM
Joined: 2008-11-05
15 posts

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:

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_dataTRUE));
        return 
$this->CI->load->view($template$this->template_data$return);
    
}

and this is a part from my folder structure:

application
 
modules
    
-front
      
views
         
partial.php
 
views
    
home.php 

When i try to load

$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

 
Posted: 30 June 2009 07:40 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-05-08
13 posts

In libraries/Template.php add:

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

In the controller:

$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.

 
Posted: 01 July 2009 07:28 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-11-05
15 posts

Hi Jérôme,

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

Regards
Mark

 
Posted: 11 July 2009 01:14 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-02
20 posts

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

 Signature 

__________________
mine of creativity  

 
Posted: 11 July 2009 01:16 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-02
20 posts

I think I got it.

 Signature 

__________________
mine of creativity  

 
Posted: 18 July 2009 07:32 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-24
29 posts

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

 
Posted: 18 July 2009 08:33 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2939 posts
kakap - 18 July 2009 11:32 AM

...how to use your library to my template?

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

$this->load->view('../../templates/header'$data); 
 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 20 July 2009 11:34 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-24
29 posts
wiredesignz - 18 July 2009 12:33 PM
kakap - 18 July 2009 11:32 AM

...how to use your library to my template?

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

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

thank you smile

but,I mean how to use this template library http://maestric.com/wiki/lib/exe/fetch.php?id=&cache=cache&media=php:ci_template_library3.zip) where my template folder is in outside of system directory ?:)

“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

 
Posted: 17 July 2010 06:12 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2010-07-07
4 posts

Hello,

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

 
Posted: 10 June 2012 05:28 AM   [ # 9 ]   [ Rating: 0 ]
Joined: 2011-08-18
24 posts
Jérôme Jaglale - 30 June 2009 07:40 PM

In libraries/Template.php add:

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

In the controller:

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

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

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:

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

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

Unable to load the requested file: menu.php