Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Extend smarty compiler for MVC

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
adel
Smarty n00b


Joined: 29 Jan 2010
Posts: 2

PostPosted: Sat Jan 30, 2010 11:43 pm    Post subject: Extend smarty compiler for MVC Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP