CodeIgniter Forums
Template Library Version 1.4.1 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Template Library Version 1.4.1 (/showthread.php?tid=12840)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24


Template Library Version 1.4.1 - El Forum - 12-30-2010

[eluser]Evollution[/eluser]
ok i change class to main and i get error :

The "header" region has already been defined.


Template Library Version 1.4.1 - El Forum - 12-31-2010

[eluser]Evollution[/eluser]
http://www.fifago.com/demo2/index.php/main why i am getting this error


Template Library Version 1.4.1 - El Forum - 12-31-2010

[eluser]WanWizard[/eluser]
Because you initialize the template twice, or add the same region twice? Difficult to guess without seeing your code.

When you load the Template library, it auto initializes the active template defined in the config file. You don't have to use set_template() yourself.


Template Library Version 1.4.1 - El Forum - 12-31-2010

[eluser]Evollution[/eluser]
config/template
Code:
$template['default']['template'] = 'template';
$template['default']['regions'] = array(
  'header',
  'title',
  'content',
  'sidebar',
  'footer',
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;
$template['default']['regions']['header'] = array('content' => array('<h1>CI Rocks!</h1>'));
$template['default']['regions']['footer'] = array('content' => array('<p id="copyright">© Our Company Inc.</p>'));

controler/main.php
Code:
&lt;?php
class Main extends CI_Controller {
  
function __construct()
    {
    parent::__construct();

    }

  
   function index()
   {
      // Write to $title
      $this->template->write('title', 'Welcome to the Template Library Docs!');
      
      // Write to $content
      $this->template->write_view('content', 'post');
      
      // Write to $sidebar
      $this->template->write_view('sidebar', 'common/sidebar');
      
      // Render the template
      $this->template->render();
   }
  
}
?&gt;

view/template.php
Code:
&lt;html&gt;
   &lt;head&gt;
      &lt;title&gt;&lt;?= $title ?&gt;&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="main.css" /&gt;
   &lt;/head&gt;
   &lt;body&gt;
      <div id="wrapper">
         <div id="header">
            &lt;?= $header ?&gt;
         </div>
         <div id="main">
            <div id="content">
               <h2>&lt;?= $title ?&gt;</h2>
               <div class="post">
                  &lt;?= $content ?&gt;
               </div>
            </div>
            <div id="sidebar">
               &lt;?= $sidebar ?&gt;
            </div>
         </div>
         <div id="footer">
            &lt;?= $footer ?&gt;
         </div>
      </div>
   &lt;/body&gt;
&lt;/html&gt;



Template Library Version 1.4.1 - El Forum - 01-01-2011

[eluser]WanWizard[/eluser]
Look at the array created in config/template, and you'll see you define 'header' and 'footer' twice.
Once as value of the region array, and once as key value in that same array.
Do a var_dump() to see what it looks like.

If you use
Code:
$template['default']['regions']['header'] = ...
remove it from the regions definition.


Template Library Version 1.4.1 - El Forum - 01-01-2011

[eluser]Evollution[/eluser]
ok i removed and now i shoud only change &lt;?= $header ?&gt; with my code yes ?


Template Library Version 1.4.1 - El Forum - 01-01-2011

[eluser]WanWizard[/eluser]
Don't know what you mean. Your template looks ok to me (altough I wouldn't use &lt;?=, but use &lt;?php echo).


Template Library Version 1.4.1 - El Forum - 01-07-2011

[eluser]Evollution[/eluser]
i'm getting a new error :
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Main::$template

Filename: controllers/main.php

Line Number: 14

Fatal error: Call to a member function write() on a non-object in /home/fifagoc1/public_html/demo2/system/application/controllers/main.php on line 14

Code:
&lt;?php
class Main extends CI_Controller {
  
function __construct()
    {
    parent::__construct();

    }

  
   function index()
   {
      // Write to $title
      $this->template->write('title', 'Welcome to the Template Library Docs!');
      
      // Write to $content
      $this->template->write_view('content', 'main');
      
      // Write to $sidebar
      
      // Render the template
      $this->template->render();
   }
  
}
Line 14: $this->template->write('title', 'Welcome to the Template Library Docs!');


Template Library Version 1.4.1 - El Forum - 02-16-2011

[eluser]steelaz[/eluser]
Updated line #443 in Template.php (1.4.1) from
Code:
$filepath = base_url() . $script;
to
Code:
$filepath = (substr(strtolower($script), 0, 4) == 'http') ? $script : base_url() . $script;

so CDN scripts could be added:
Code:
$this->template->add_js('https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');



Template Library Version 1.4.1 - El Forum - 03-03-2011

[eluser]nsbingham[/eluser]
Evollution - I'm experiencing the same error. Were you able to figure it out?