A ridiculously simple Smarty 3 Spark for CodeIgniter 2
This project is no longer maintained, and will receive no updates or support. Use at your own discretion.
- Get Sparks.
- In a terminal,
cd
to your project root and typephp tools/spark install smartyview
. - Create the necessary folders in the locations specified in the Smartyview config file.
- Add Smartyview to your Sparks autoload array:
$autoload['sparks'] = array('smartyview/x.x.x');
Or, load it manually in your controllers/models/whatever:
$this->load->spark('smartyview/x.x.x');
Please remember to use the real version number of the Spark you installed!
First, you need to create your data array, just like you would for "normal" views.
$data = array(
'title' => 'My Page',
'subtitle' => 'My Subtitle',
'etc' => '...'
);
Normally at this point, you would use $this->load->view('viewfile', $data)
to output your content, but to render a Smarty template, you will do this instead:
$this->smartyview->render('my-template.tpl', $data);
By default, your template files will be stored in your application/views/
directory, and should be named with either a .tpl
or .php
extension. You can change the templates directory in the Smartyview config file.
That's it!
They have great docs... check them out.
In your templates, you should be able to call any CodeIgniter functions, as long as they are enclosed in curly braces:
{anchor('pages/test', 'Test Page')}
However, if you are calling any CodeIgniter objects using the $this
keyword, you will need to use $CI
instead:
{$CI->uri->uri_string()}