Skip to content

Instantly share code, notes, and snippets.

@vimalmistry
Forked from nambok/template.php
Created June 3, 2016 20:19
Show Gist options
  • Save vimalmistry/32dfe505f01b23d79df3f87de8762534 to your computer and use it in GitHub Desktop.
Save vimalmistry/32dfe505f01b23d79df3f87de8762534 to your computer and use it in GitHub Desktop.
Template class
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Template{
/*
* variables
*/
/**
* CI
*
* @var CI object
* @access public
*/
public $CI;
/**
* template
*
* @var String
* @access private
*/
public $template = 'default';
/**
* head
*
* @var String
* @access private
*/
private $head = null;
/**
* footer
*
* @var String
* @access private
*/
private $footer = null;
/**
* page_data
*
* @var String
* @access private
*/
private $pageData = null;
// --------------------------------------------------------------------
/**
*
*/
public function __construct()
{
log_message('debug', "Template Class initialized");
parent::__construct();
$this->CI =& get_instance();
$this->CI->config->load('tl_config');
}
// --------------------------------------------------------------------
/**
* set template
*/
public function set_template($template)
{
$this->template = $template;
}
// --------------------------------------------------------------------
/**
*
*/
public function __render_json($success, $message, $data_dt = array()){
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$data = array( "success" => $success,
"message" => $message,
"data" => $data_dt
);
//nothing else should be executed
$this->CI->load->view("base/json", $data);
//echo json_encode($data_dt);
//exit(0);
}
// --------------------------------------------------------------------
/**
*
*/
public function __render_head( $title = "",
$description = "",
$js = array(),
$jsFooter = array(),
$css = array(),
$head = array()){
$data["title"] = ( empty($title) ? $this->CI->config->item($this->template.'_title') : $title );
$data["description"] = ( empty($description) ? $this->CI->config->item($this->template.'_description') : $description );
$data["headJS"] = ( ( is_array($js) && sizeof($js) ) ? $js : $this->CI->config->item($this->template.'_headJS') );
$data["headCSS"] = ( ( is_array($css) && sizeof($css) ) ? $css : $this->CI->config->item($this->template.'_headCSS') );
$this->head = $this->CI->load->view("base/html/head", $data, TRUE);
$data = array();
$data["footerJS"] = ( ( is_array($jsFooter) && sizeof($jsFooter) ) ? $jsFooter : $this->CI->config->item($this->template.'_footerJS') );
$this->footer = $this->CI->load->view("base/html/footer", $data, TRUE);
}
// --------------------------------------------------------------------
/**
*
*/
public function __build_data($template, $data = array(), $return = FALSE){
if($return)
return $this->CI->load->view($this->template."/template/".$template, $data, TRUE);
else
$this->pageData = $this->CI->load->view($this->template."/template/".$template, $data, TRUE);
}
// --------------------------------------------------------------------
/**
*
*/
public function __render_template($data = array(), $layout = "1-column", $customTemplate = ''){
if( !$this->head )
{
$this->__render_head();
}
$this->template = (!empty($customTemplate) ? $customTemplate : $this->template);
$data["templateHead"] = $this->head;
$data["templateData"] = $this->pageData;
$data["templatefooter"] = $this->footer;
$this->CI->load->view($this->template."/layout/".$layout, $data);
}
// --------------------------------------------------------------------
/**
*
*/
public function getPath($path){
return $this->template."/template/".$path;
}
// --------------------------------------------------------------------
}
// END Template Class
/* End of file template.php */
/* Location: ./application/libraries/template.php */
?>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* TEMPLATE HEAD SETTINGS
*
*/
$config["default_title"] = "DEFAULT TITLE";
$config["admin_title"] = "DEFAULT ADMIN TITLE";
$config["default_description"] = "default description";
$config["admin_description"] = "";
//headJS
$config["default_headJS"] = array(
""
);
$config["default_footerJS"] = array(
""
);
//headJS admin
$config["admin_headJS"] = array(
""
);
$config["admin_footerJS"] = array(
""
);
//css head
$config["default_headCSS"] = array(
"main" => array(
""
),
"ie" => ""
);
//css admin
$config["admin_headCSS"] = array(
"main" => array(
""
),
"ie" => ""
);
/* End of file tl_config.php */
/* Location: ./application/config/tl_config.php */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment