Welcome Guest, Not a member yet? Register   Sign In
How to add multiple themes to your CI app - Wordpress-like theming for CI
#1

[eluser]JoostV[/eluser]
Use the following setup if you wish
- to use multiple themes for your CI app, like in Wordpress;
- while leaving your application folder and system folder outside of the webroot.

First of all, the folder structure:
/application
/config
/other application folders
/system
/cache
/codeigniter system folders
/public_html
/themes
/default
/views
/css
/jscripts
/images
/some-other-theme
.htaccess
index.php

First, edit the following lines in you index.php so CI can find the application and system folders.
Code:
$system_folder = "../system";
$application_folder = "../application";

And now... theming!

Create a file MY_Loader.php in your application/libraries folder. This file will extend default the CI_Loader class, adding some handy theming functionality to $this->load.

MY_Loader.php
Code:
/**
* @category   Accent Interactive CMS
* @package    Accent_Library
* @name MY_Loader.php
* @version 1.0
* @author Joost van Veen
* @copyright Accent Interactive
*/
class MY_Loader extends CI_Loader
{
    // Set the default theme. Make sure this folder exists!
    public $theme = 'default';
    
    public function __construct() {
        parent::CI_Loader();
        // Set the loader to use the default theme path.
        $this->set_theme($this->theme);
    }
    
    /**
     * Set the theme location. This is where the loader class will look for view files.
     * his location is in the webroot, like public_html/themes/default.
     * New theme? Upload all views, css, images, jascripts to public_html/themes/my-new-theme
     * @param string $theme_name
     * @return void
     */
    public function set_theme($theme_name){
        $this->theme = $theme_name;
        $this->_ci_view_path = FCPATH . 'themes/' . $this->theme . '/views/';
    }
}

Now you can easily switch between views in your controller, or your MY_Controller.

Controller
Code:
// Get theme from database and set it
$theme_name = $this->settings->theme;
$this->load->set_theme($theme_name);

// Do a lot of other stuff

// Load the view, for instance 'pages'
$this->load->view('pages');

Because the entire theme (view files, css, jscripts, etc) is in a single folder you can drop new themes into the /themes folder and use them at the drop of a hat.


Messages In This Thread
How to add multiple themes to your CI app - Wordpress-like theming for CI - by El Forum - 01-19-2010, 02:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB