|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
adel Smarty n00b
Joined: 29 Jan 2010 Posts: 2
|
Posted: Sat Jan 30, 2010 11:43 pm Post subject: Extend smarty compiler for MVC |
|
|
I implemented a MVC and I used smarty 2 as template engine in view helpers:
please help me to upgrade below code from smarty 2 to 3:
Code: |
class MySmartyCompiler extends Smarty_Compiler
{
function __construct() {
parent::__construct();
}
function _compile_compiler_tag($tagCommand, $tagArgs, &$output)
{
//We first try to use Smarty's own functionality to parse the tag
$found = parent::_compile_compiler_tag($tagCommand, $tagArgs, $output);
if(!$found)
{
$paramCode = $this->_createParameterCode($tagArgs);
$output = "<?php echo \$this->callViewHelper('$tagCommand', $paramCode); ?>";
$found = true;
}
return $found;
}
private function _createParameterCode($tagArgs)
{
$i = 1;
if($tagArgs !== null)
{
$params = explode(' ', $tagArgs);
$cntParams = count($params);
foreach($params as $p)
{
//Split each key=value pair to vars
list($key, $value) = explode('=', $p, 2);
//Use Smarty's own functions to parse the value
//so that if there's a variable, it gets changed to
//properly point at a template variable etc.
$value = $this->_parse_var_props($value);
$code .= "'$key'=>$value";
if($i != $cntParams)
{
$code .= ',';
}
$i++;
}
}
return "array($code)";
}
}
?>
|
Regards,
Adel Khaleghi |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|