Welcome Guest, Not a member yet? Register   Sign In
Simple Theme Support
#1

[eluser]Filippo Toso[/eluser]
Here is a simple Loader extensio that provide transparent support for themes.

Code:
<?php

/**
* MY_Loader Class
*
* Extends the Loader class to add support for themes
*
* @package     CodeIgniter
* @subpackage  Libraries
* @author      Filippo Toso
* @category    Loader
*
* This class uses the $config['theme_name'] setting to load the view
* files from the /views/{theme_name} folder.
*
* If the view doesn't exist, the class tries to load it from the
* /views/default folder
*
* If the view can't be found even in the default folder, the class
* relies on the default behavior of the Loader class.
*/

class MY_Loader extends CI_Loader {

    function view($view, $vars = array(), $return = FALSE)
    {    

        $theme_name = config_item('theme_name');

        $ext = pathinfo($view, PATHINFO_EXTENSION);
        $file = ($ext == '') ? $view.EXT : $view;

        // Verify if /view/{theme_name}/$view.php exists
        if (($theme_name !== FALSE) && file_exists($this->_ci_view_path . $theme_name . '/' . $file))
        {
            $view =  $theme_name . '/' . $view;
        }
        // Otherwise verify if /view/default/$view.php exists
        elseif (file_exists($this->_ci_view_path . 'default/'  . $file))
        {
            $view = 'default/' . $view;
        }
        // Otherwise behaves as usual        

        return parent::view($view, $vars, $return);
        
    }    

}

/* End of file MY_Loader.php */
/* Location: ./application/libraries/MY_Loader.php */


Messages In This Thread
Simple Theme Support - by El Forum - 06-20-2010, 05:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB