CodeIgniter Forums
Template library of Colin Williams not working [Solved] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Template library of Colin Williams not working [Solved] (/showthread.php?tid=30088)



Template library of Colin Williams not working [Solved] - El Forum - 05-03-2010

[eluser]ajitabhpandey[/eluser]
Hi,

I have recently started using CodeIgnitor for few of my projects. I am using the template library version 1.4.1 from Colin Williams (http://www.williamsconcepts.com/ci/codeigniter/libraries/template/). After following the instruction to place the files in application/config, application/library and application/view, I made the following change in index function of "welcome" controller which comes with the default code ignitor code.

Code:
function index()
    {
        //$this->load->view('welcome_message');
        $this->template->render();
    }

When I visit the URL http://localhost, this is what I get:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$template

Filename: controllers/welcome.php

Line Number: 13

Any hints as to what am I doing wrong.


Template library of Colin Williams not working [Solved] - El Forum - 05-03-2010

[eluser]theprodigy[/eluser]
do you have template.php in your config folder, and does it contain the necessary $template array as specified in http://www.williamsconcepts.com/ci/codeigniter/libraries/template/reference.html?


Template library of Colin Williams not working [Solved] - El Forum - 05-04-2010

[eluser]ajitabhpandey[/eluser]
Yes I have the following line:

Code:
$template['default']['template'] = 'template';

I have tried adding a php extension as follows, but it did not work as well.

Code:
$template['default']['template'] = 'template.php';



Template library of Colin Williams not working [Solved] - El Forum - 05-04-2010

[eluser]steelaz[/eluser]
Looks like Template library is not loaded, try adding this line before using $this->template

Code:
$this->load->library('template');



Template library of Colin Williams not working [Solved] - El Forum - 05-05-2010

[eluser]ajitabhpandey[/eluser]
Yep, works like a charm. I thought any libraries put in applications/libraries folder should be loaded automatically. At-least that's what happening in one of the other projects where a custom php file in application/libraries directory is being auto-loaded.

Thanks for pointing that out.


Template library of Colin Williams not working [Solved] - El Forum - 05-05-2010

[eluser]steelaz[/eluser]
Most of the time you don't need to use all libraries in a single controller, so I think it's better to load them when you need them. For libraries that you use in most controllers, such as Template, you can auto-load them by editing /application/config/autoload.php