Skip to content

External View Plugin

Zoe Bogner edited this page Jun 25, 2013 · 3 revisions

This plugin behaves the same as the default $this->load->view() except it allows you to include files outside your root application view folder. It will change the path, include the file, then change the path back to the original. Nice to have when using shared templates over multiple sites.

= SOURCE CODE =

<?php
/* !DESCRIPTION: This method behaves the same as the default $this->load->view() except it allows you to
include files outside your root application view folder. It will change the path, include the file, 
then change the path back to the original. Nice to have when using shared templates over multiple sites.
*/

//!VAR -> $path :: The absolute path to the view folder (IE: /var/shared/codeigniter/views/)
//!VAR -> $view :: The view file name (IE: shared-header)
//!VAR -> $data :: The variables and values you wish to pass to the view, if any (Defaults to empty array())
//!VAR -> $return :: Set to TRUE if you want to return the value rather than add to the view (Defaults to FALSE)

function external_view($path, $view, $data=array(), $return=FALSE)
{
    $__ci =& get_instance();
    $op = $__ci->load->_ci_view_path;
    $__ci->load->_ci_view_path = $path;
    $v = $__ci->load->view($view, $data, $return);
    $__ci->load->_ci_view_path = $op;
    if ($return === TRUE) { return $v; }
}
?>
Clone this wiki locally