Welcome Guest, Not a member yet? Register   Sign In
Template Library Version 1.4.1

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

The "header" region has already been defined.

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

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

[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;

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

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

[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).

[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!');

[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');

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




Theme © iAndrew 2016 - Forum software by © MyBB