Part of the EllisLab Network
   
 
HMVC and Layout Template Library
Posted: 29 June 2009 07:37 AM   [ Ignore ]  
Summer Student
Total Posts:  15
Joined  11-05-2008

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

Profile
 
 
Posted: 30 June 2009 06:40 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  16
Joined  05-08-2007

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.

Profile
 
 
Posted: 01 July 2009 06:28 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  15
Joined  11-05-2008

Hi Jérôme,

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

Regards
Mark

Profile
 
 
Posted: 11 July 2009 12:14 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  22
Joined  07-02-2009

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  

Profile
 
 
Posted: 11 July 2009 12:16 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  22
Joined  07-02-2009

I think I got it.

 Signature 

__________________
mine of creativity  

Profile
 
 
Posted: 18 July 2009 06:32 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  30
Joined  10-24-2008

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

Profile
 
 
Posted: 18 July 2009 07:33 AM   [ Ignore ]   [ # 6 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3193
Joined  06-10-2007
kakap - 18 July 2009 10: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

Profile
 
 
Posted: 20 July 2009 10:34 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  30
Joined  10-24-2008
wiredesignz - 18 July 2009 11:33 AM
kakap - 18 July 2009 10: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

Profile
 
 
Posted: 17 July 2010 05:12 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  6
Joined  07-07-2010

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.

Profile