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:
- get_theme_url()
- theme_url()
- get_theme_path()
- theme_path()
- get_upload_url()
- upload_url()
- get_upload_path()
- upload_path()
- get_common_url()
- common_url()
- get_common_path()
- common_path()
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 (public_html, 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.
##Library Methods
- set: sets variables to pass to view files.
- get: get something from theme config property.
- theme: changes the current theme.
- master: changes the master view file to use.
- layout: use a different layout.
- title, description, keywords: set page's meta tags content.
- add_meta, meta: the first one appends a meta tag and the other one displays the full html <meta> tag.
- assets_url and uploads_url: both return the full URL to their respective folders. (content/assets and content/uploads)
- Methods on CSS and JS (I use x to represente them both):
- add_x: adds the file to files list.
- prepend_x: adds the at the beginning of files list.
- remove_x: remove a file from files list.
- replace_x: replaces a file by a new one.
- get_x: returns an array of loaded X files.
- x_url: returns the full url to X file.
- x: css() or js() display full html tag with the given file.
CI-Theme library looks for views in a particular order so that everything can be overridden. Here is in order where files should be:
- themes/theme_name/views/_modules/module_name/
- themes/theme_name/views/
- module_location/module_name/views/
- views_path (which is by default APPPATH/views/)
- themes/theme_name/views/_modules/module_name/_partials/
- themes/theme_name/views/_partials/
- module_location/module_name/views/_partials/
- views_path/_partials/
- themes/theme_name/views/_modules/module_name/_layouts/
- themes/theme_name/views/_layouts/
- module_location/module_name/views/_layouts/
- views_path/_layouts/.
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:
- themes/theme_name/views/_modules/module_name/_master/
- themes/theme_name/views/_master/
- module_location/module_name/views/_master/
- views_path/_master/
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.
#CREDITS All credits go to their respective owners: CodeIgniter, Bootstrap, Semantic-UI and Ericbarnes. (and some of it for my work :D)