Codeigniter is an awesome framework, it’s idea of a parser library that ships with it is not. I have written a simple library that extends Codeigniter’s native view loading to allow you to use Smarty 3 in your Codeigniter projects to render your views.
Requirements:
- Codeigniter 2.0 as this library uses the core and third_party folders, although with some changes it will work with 1.7.2 / 1.7.3 versions of Codeigniter.
Features:
- Extends native Codeigniter view loading so you can still use $this->load->view() to load your templates. This also means that if your Codeigniter application is using $this->load->view() you won’t need to change any of your code to use this library.
- Allows you to use Smarty specific features including template inheritance inside of your views.
- Uses your views directory for loading templates but the location of views can be changed if you don’t use the standard CI views folder.
- Comes bundled with the latest version of Smarty already.
Install:
Copy all of the files from the download zip off the repo into your application directory. Then you should be able to just load Smarty views using the native $this->load->view() notation.
Download:
Download this library fresh off the press on it’s own Github repository, here.
Update Log:
- Thursday, 17th February 2011 – Added in configuration file. Added in default needed cache directories. A change to note from a few days ago is the CI superobject is assigned by reference to the views using the variable name “this” which means you should be able to go $this->load->view() inside of your views or any other native CI stuff (all untested though).
- Friday, 3rd December 2010 – Added in check for a file extension, if no file extension is found views will search for a file with a .php extension much like standard CI view loading works.
Feel free to post improvements and recommendations below if you’ve made some improvements or found that it doesn’t function correctly.
Note: Keep in mind that in this package I am using a custom MY_Loader file in the core directory to extend the native view functionality of Codeigniter, so if you are using Modular CI, Modular Extensions or already have a custom MY_Loader file in your core directory you might want to copy and paste the code into the pre-existing file yourself or you may lose existing functionality.