[eluser]kimo_gusatava[/eluser]
I just want to post/share this simple HTML parser/templater? I made
Not much but here we go...
Please take note of the <s/cript (remove the / )
Code:
<?php
/**
* Description of templater
*
* @author jatazoulja
*/
class MY_tpl_helper {
public $header;
public $footer;
public $nav;
public $CI;
public $config;
public $title;
public $meta;
public $js;
public $css;
function __construct() {
$this->CI = & get_instance();
$this->init();
$this->CI->load->helper('html');
}
function init() {
$this->config = parse_ini_file(APPPATH . 'config/htmlTemplate.ini', TRUE);
return $this;
}
function title($prefix='', $suffix='') {
if (!isset($this->config['siteInfo']['title'])) {
return $this->title = FALSE;
} else {
return $this->title = '<title>' . $prefix . '' . $this->config['siteInfo']['title'] . '' . $suffix . '</title>';
}
}
function meta($name='', $desc='') {
if (!isset($this->config['meta'])) {
return $this->meta = FALSE;
} else {
$meta = $this->config['meta'];
$arMeta = array();
foreach ($meta as $k => $v) {
for ($i = 0; $i < sizeof($v); $i++) {
$arMeta[$i][$k] = $v[$i];
}
}
return $this->meta = meta($arMeta);
}
}
function js($src='') {
$this->js = "\n<!-- Js Scripts STARTS -->\n\n";
$this->js .= "<s/cript>";
$this->js .= "var base_url = '".base_url()."'";
$this->js .= "[removed]\n";
if (!isset($this->config['script']) AND $src == '') {
$this->js .= "\n<!-- Please edit the ini file to include stylesheets -->\n\n";
} else {
$script = $this->config['script']['src'];
$arJs = array();
$basePath = base_url() . '' . $this->config['script']['folder'];
for ($i = 0; $i < sizeof($script); $i++) {
$this->js .= "<s/cript type='text/javascript' src='{$basePath}{$script[$i]}'>[removed]\n";
}
if ($src != '') {
$this->js .= "<s/cript type='text/javascript' src='{$basePath}$src'>[removed]\n";
}
}
return $this->js .= "\n<!-- Js Scripts ENDS -->\n\n";
}
function css($src='', $rel2='stylesheet') {
$this->css = "\n<!-- link include starts -->\n\n";
if (!isset($this->config['css']) AND $src == '') {
return $this->css .= "<!-- Please edit the ini file to include stylesheets */ \n";
} else {
$basePath = base_url();
foreach ($this->config['css'] as $key => $value) {
$rel = "rel='$key'";
foreach ($value as $k) {
$this->css .= "<link $rel href='{$basePath}$k' />\n";
}
}
if ($src != '') {
$this->css .= "<link rel='$rel2' href='$src' />\n";
}
}
return $this->css .= "\n<!-- link include Ends -->\n\n";
}
function header() {
$head = '<head>';
if (!$this->meta) {
$this->meta();
}
if (!$this->title) {
$this->title();
}
if (!$this->js) {
$this->js();
}
$head .= $this->meta;
$head .= $this->title;
$head .= $this->css;
$head .= $this->js;
$head .= '</head>';
return $this->header = $head;
}
function html($tpl='',$data = '') {
//echo doctype('html5');
echo '<html>';
echo $this->header();
if(is_array($tpl)) {
foreach($tpl as $k) {
echo $this->CI->load->view($k, $data, TRUE);
}
} else {
echo $this->CI->load->view($tpl, $data, TRUE);
}
echo '</html>';
}
}
How to use:
Code:
$this->my_tpl_helper->css('css/test.css');
$this->my_tpl_helper->js('exportAll.js');
$tpl = "secure/index";
$data['tester'] = "null";
$this->my_tpl_helper->html($tpl, $data);
Config file (located at the config directory) htmlTemplate.ini
Code:
[meta]
name[] = "X-UA-Compatible"
name[] = "Keyword"
name[] = "robots"
name[] = "viewport"
content[] = "IE=9,chrome=1"
content[] = "love, passion, intrigue, deception"
content[] = "no-cache"
content[] = "width=device-width, initial-scale=1.0"
[script]
folder = "js/"
src[] = "jquery-1.5.1.min.js"
src[] = "jquery-ui-1.8.12.custom.min.js"
src[] = "jquery.dataTables.js"
src[] = "plugins.js"
src[] = "script.js"
[css]
icon[] = "favicon.ico"
apple-touch-icon[] = "apple-touch-icon.png"
stylesheet[] = "css/black-tie/jquery-ui-1.8.12.custom.css"
stylesheet[] = "css/demo_page.css"
stylesheet[] = "css/demo_table.css"
stylesheet[] = "css/style.css"
stylesheet[] = "css/handheld.css"
[siteInfo]
title = 'CompanyX:Fix Leads'
compName = 'CompanyX'
cheers!