Welcome Guest, Not a member yet? Register   Sign In
My_Template class
#1

[eluser]walrus_lt[/eluser]
Hello, i'm trying to create my own tpl class wich allow me to load different tpl's views...
But my OOP experience is very poor Sad I'm getting errors and don't know what to do.

This is my code
Code:
<?php
  // application/project/libraries/My_Template.php
  class My_Template extends CI_Loader
  {
    public static $template;

    function My_Template()
    {
      parent::CI_Loader();
      set_template();
    }

    function set_template($template=null){
      if ($template == null){
      /* TODO later
        if (session){
          self::$template = $session->item('template');
        } else {
      */
        self::$template = $this->config->item('template');
      } else {
        self::$template = $template;
      }
    }

    function load_view($view, $data=array(), $master=0){
      if ($master){
        return $this->load->view(self::$template.'/', $data);
      } else {
        return $this->load->view(self::$template.'/templates/'.$view, $data);
      }
    }
  }

?>

This class was loaded by ci, from autoload array,.... :/ Could some one help to make this class working? :-S
#2

[eluser]Pascal Kriete[/eluser]
Why are you extending the Loader?

I think you need to take a step back and think about what you want to do. Could you tell us how you want it to work (once it's done) - I'm sure someone will have some pointers. Also, have you read about creating libraries?
#3

[eluser]ericsodt[/eluser]

If interested in using my idea.. my 'template' system works like struts tiles (j2ee programming - if not familiar)



I have a simple layout file [siteLayout.php]

Code:
<?
    include('header.php');


    $this->load->view($content);


    include('footer.php');
?>


Then from my controllers I 'inject' my content


Code:
$data = array(
               'title' => 'My Page',
               'content' => 'home',
               'breadcrumbs'=>< breadCrumbInfomation >
        );

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


As you can see I load siteLayout, then inject the contents of home.php into it below the header and above the footer.



This is a real simple way to do templating and works well for me. I hope it does the same for you



Cheers




Theme © iAndrew 2016 - Forum software by © MyBB