4  * Smarty Internal Plugin Compile Eval
 
   6  * Compiles the {eval} tag 
 
  13  * Smarty Internal Plugin Compile Eval Class
 
  15 class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase {
 
  16     public $required_attributes = array('var');
 
  17     public $optional_attributes = array('assign'); 
 
  18     public $shorttag_order = array('var','assign');
 
  21      * Compiles code for the {eval} tag
 
  23      * @param array $args array with attributes from parser
 
  24      * @param object $compiler compiler object
 
  25      * @return string compiled code
 
  27     public function compile($args, $compiler)
 
  29         $this->compiler = $compiler; 
 
  30         $this->required_attributes = array('var');
 
  31         $this->optional_attributes = array('assign'); 
 
  32         // check and get attributes
 
  33         $_attr = $this->_get_attributes($args); 
 
  34         if (isset($_attr['assign'])) {
 
  35               // output will be stored in a smarty variable instead of beind displayed
 
  36             $_assign = $_attr['assign'];
 
  39         // create template object
 
  40         $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.".$_attr['var'].", \$_smarty_tpl->smarty, \$_smarty_tpl);"; 
 
  41         //was there an assign attribute? 
 
  42         if (isset($_assign)) {
 
  43             $_output .= "\$_smarty_tpl->assign($_assign,\$_template->getRenderedTemplate());";
 
  45             $_output .= "echo \$_template->getRenderedTemplate();";
 
  47         return "<?php $_output ?>";