4  * Smarty Internal Plugin Compile Assign
 
   6  * Compiles the {assign} tag
 
  14  * Smarty Internal Plugin Compile Assign Class
 
  16 class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
 
  18      * Compiles code for the {assign} tag
 
  20      * @param array $args array with attributes from parser
 
  21      * @param object $compiler compiler object
 
  22      * @param array $parameter array with compilation parameter
 
  23      * @return string compiled code
 
  25     public function compile($args, $compiler, $parameter)
 
  27         $this->compiler = $compiler;
 
  28         // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
 
  29         $this->required_attributes = array('var', 'value');
 
  30         $this->shorttag_order = array('var', 'value');
 
  31         $this->optional_attributes = array('scope');
 
  34         // check and get attributes
 
  35         $_attr = $this->_get_attributes($args); 
 
  37         if ($this->compiler->tag_nocache || $this->compiler->nocache) {
 
  39             // create nocache var to make it know for further compiling
 
  40             $compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
 
  43         if (isset($_attr['scope'])) {
 
  44             $_attr['scope'] = trim($_attr['scope'], "'\"");
 
  45             if ($_attr['scope'] == 'parent') {
 
  46                 $_scope = Smarty::SCOPE_PARENT;
 
  47             } elseif ($_attr['scope'] == 'root') {
 
  48                 $_scope = Smarty::SCOPE_ROOT;
 
  49             } elseif ($_attr['scope'] == 'global') {
 
  50                 $_scope = Smarty::SCOPE_GLOBAL;
 
  52                 $this->compiler->trigger_template_error('illegal value for "scope" attribute', $this->compiler->lex->taglineno);
 
  56         if (isset($parameter['smarty_internal_index'])) {
 
  57             return "<?php if (!isset(\$_smarty_tpl->tpl_vars[$_attr[var]]) || !is_array(\$_smarty_tpl->tpl_vars[$_attr[var]]->value)) \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];?>";
 
  59             return "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>";