3 * Smarty Internal Plugin Compile Eval
5 * Compiles the {eval} tag.
13 * Smarty Internal Plugin Compile Eval Class
16 * @subpackage Compiler
18 class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase {
21 * Attribute definition: Overwrites base class.
24 * @see Smarty_Internal_CompileBase
26 public $required_attributes = array('var');
28 * Attribute definition: Overwrites base class.
31 * @see Smarty_Internal_CompileBase
33 public $optional_attributes = array('assign');
35 * Attribute definition: Overwrites base class.
38 * @see Smarty_Internal_CompileBase
40 public $shorttag_order = array('var','assign');
43 * Compiles code for the {eval} tag
45 * @param array $args array with attributes from parser
46 * @param object $compiler compiler object
47 * @return string compiled code
49 public function compile($args, $compiler)
51 $this->required_attributes = array('var');
52 $this->optional_attributes = array('assign');
53 // check and get attributes
54 $_attr = $this->getAttributes($compiler, $args);
55 if (isset($_attr['assign'])) {
56 // output will be stored in a smarty variable instead of beind displayed
57 $_assign = $_attr['assign'];
60 // create template object
61 $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'.".$_attr['var'].", \$_smarty_tpl->smarty, \$_smarty_tpl);";
62 //was there an assign attribute?
63 if (isset($_assign)) {
64 $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
66 $_output .= "echo \$_template->fetch();";
68 return "<?php $_output ?>";