Yeah, if someone finds out the solution themselves, they should actually post the solution. There's nothing more infuriating than looking for a solution on Google only to find the OP said they found the solution and didn't say how.
Sure.
I'm not able to test this but, this should work. Hopefully, so ergo my original point something like this...
Code:
require_once(SMARTY_DIRECTORY . 'Smarty.class.php');
namespace Core
{
class Template
{
private $_smarty;
private $_globalAssigns = array (
'thedate' => time()
);
function __construct()
{
$this->_smarty = new \Smarty();
$this->_smarty->compile_dir = SMARTY_COMPILE_DIR; // Define your compile directory.
$this->_smarty->debugging = SMARTY_DEBUG; // Define a bool.
$this->_smarty->cache_lifetime = SMARTY_CACHE_LIFETIME // Define how long you want to cache for.
$this->_smarty->compile_check = SMARTY_COMPILE_CHECK // I usually set this to false.
$this->_smarty->caching = SMARTY_CACHING // I set this to 0. (0,1).
$this->_smarty->template_dir = SMARTY_TEMPLATE_DIRECTORY; // I would strongly suggest having a template folder.
}
/**
* Pointless Alias functionality for smarty...
*
* @param String $key
* @param Array $data
* @return Void
*
*/
private function _assign($key, $data)
{
$this->_smarty->assign($key, $data);
}
/**
* Small function to load template files from within a define template directory.
*
* @param String $templatePath
* @param Array $data
* @return Void
*/
public function display($templatepath, $data)
{
// Assign the global template data.
$this->_assign('globals', $this->_globalAssigns);
// Assign the template specific data.
if (isset($data))
{
foreach ($data as $key => $value)
{
$this->_assign($key, $value);
}
}
// Display the template.
if ($templatepath)
{
$this->_smarty->display ($templatepath);
}
}
}
}
Just create an object of template and load up the files through some templating system