-
Notifications
You must be signed in to change notification settings - Fork 0
Setup with Smarty
Below is the easiest way to setup Smarty without having to rewrite any of your code (besides views).
http://www.smarty.net/download
Extract Smarty libs directory to app/core/. Rename folder to smarty. Path to Smarty should now be app/core/smarty/Smarty.class.php.
Optional: Rename folder to include version number. Ex: app/core/smarty_3.1.7/.
Create folder app/views/compiled with write access.
Open app/core/load.php.
Add to the __construct the follow:
define('SMARTY_DIR', $this->root.'app/core/smarty/');
require_once('Smarty.class.php');
$this->smarty = new Smarty();
$this->smarty->template_dir = $this->root.'app/views/';
$this->smarty->compile_dir = $this->root.'app/views/compiled/';
$this->smarty->plugins_dir = $this->root.'app/helpers/';
$this->smarty->use_sub_dirs = true;Can configure Smarty more how you please. More Info
Replace the view function with:
public function view($sTemplate, $aAssign = array(), $sReturn = false) {
if($this->smarty->templateExists($sTemplate)) {
foreach($aAssign as $sName => $sValue) {
$this->smarty->assign($sName, $sValue);
}
if($sReturn == true) {
return $this->smarty->fetch($sTemplate);
} else {
$this->smarty->display($sTemplate);
}
} else {
return false;
}
}Replace the helper function with:
public function helper($sHelper, $sType = 'function') {
if(!function_exists($sHelper.'_helper')) {
if(is_file($this->root.'app/helpers/'.$sHelper.'.php')) {
include($this->root.'app/helpers/'.$sHelper.'.php');
$this->smarty->registerPlugin($sType, $sHelper, $sHelper);
if(!function_exists($sHelper.'_helper')) {
return false;
}
} else {
return false;
}
}
return true;
}Smarty should now be setup!
Usage of helpers with Smarty will modify how interaction with the function should take place. Function name does not need to change, but arguments will. Learn More