There are plenty of CodeIgniter template library. I tried most of them and I must say that they rock. Though, I had to make my own that suits my needs and that may be easy to implement, easy to understand and easy to use.
I have added Event so themes would be able to enqueue their own CSS files, JS files an meta tags. They can even manipulate html and body classes.
This is the first part of it, other things will be added later. You register as many events as you want as long as you trigger them in the library.
To see how it's done, go the provided themes functions.php files (default and semantic) to see how it's done.
Don't forget to take a look at master view files as well(default and semantic).
assets_url() removed because it was kind of useless but the following methods were added:
All methods with get_ will simply return the string while those without it will echo it.
Example:
theme_url('css/style.css'); // Output: ...com/content/themes/THEME/css/style.css
It offers you the possibility to implement theming feature to your CodeIgniter applications with simple folders structure and ease of use (It works even when using HMVC).
All you have to do is to download provided files into your CodeIgniter install and you are done. Of course, some configuration need to be done and THEN you are really done.
This library comes in two (2) parts, the first goes into your application folder and the other in your public accessible folder (_publichtml, www...)
- application
- config/theme.php
- helpers/theme_helper.php (_NOT NEEDED_)
- libraries/Theme.php
- content
- common
- themes
- default
- assets/
- views/
- _layouts/
- default.php
- _master/
- default.php
- _modules/
- _partials/
- alert.php
- footer.php
- header.php
- sidebar.php
- semantic (same as above)
- uploads
Other files are simply either css, js or images.
CI-Theme library looks for views in a particular order so that everything can be overridden. Here is in order where files should be:
The master view is named default.php by default but it can be overridden (4th parameter of Theme::load()). The library will search inside these folders in the following order:
Load the library where you want to use or you can autoload it inside autoload.php file.
$autoload['libraries'] = array('theme');
In your controller, simple use library's method or chain them (ones that can be chained). Example (see: controllers/Example.php)
$this->theme
->title('Title Goes Here')
->add_css('added_css1', 'added_css2')
->prepend_css('prepended_css1'),
->add_js('added_js1'),
->prepend_js('prepended_js1')
->add_partial('header')
->load('view_file', $data);
There is a short version of all this but in case you want to add partial views you have to use $this->theme->add_partial()
before using the function.
$this->theme
->add_partial('header')
->add_partial('footer');
render('view_file', $data, 'Title Goes Here', array(
// Available options.
'css' => array('added_css1', 'added_css2'),
'prepend_css' => 'prepended_css1',
'js' => 'added_js1',
'prepend_js' => 'prepended_js1',
));
Feel free to explore the library to know more about it and if you have any questions, I am here to answer as long as I am still alive.
All credits go to their respective owners: CodeIgniter, Bootstrap, Semantic-UI and Ericbarnes. (and some of it for my work :D)