smarty_internal_compile_append.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Append
  4. *
  5. * Compiles the {append} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Append Class
  13. */
  14. class Smarty_Internal_Compile_Append extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the {append} tag
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return string compiled code
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->required_attributes = array('var', 'value');
  26. $this->optional_attributes = array('scope', 'nocache', 'index');
  27. $_nocache = 'null';
  28. $_scope = 'null';
  29. // check for nocache attribute before _get_attributes because
  30. // it shall not controll caching of the compiled code, but is a parameter
  31. if (isset($args['nocache'])) {
  32. if ($args['nocache'] == 'true') {
  33. $_nocache = 'true';
  34. $_nocache_boolean = true;
  35. }
  36. unset($args['nocache']);
  37. }
  38. // check and get attributes
  39. $_attr = $this->_get_attributes($args);
  40. if (isset($_attr['scope'])) {
  41. if ($_attr['scope'] == '\'parent\'') {
  42. $_scope = SMARTY_PARENT_SCOPE;
  43. } elseif ($_attr['scope'] == '\'root\'') {
  44. $_scope = SMARTY_ROOT_SCOPE;
  45. } elseif ($_attr['scope'] == '\'global\'') {
  46. $_scope = SMARTY_GLOBAL_SCOPE;
  47. }
  48. }
  49. // compiled output
  50. if (isset($_attr['index'])) {
  51. return "<?php \$_smarty_tpl->append($_attr[var],array($_attr[index] => $_attr[value]),true,$_nocache,$_scope);?>";
  52. } else {
  53. return "<?php \$_smarty_tpl->append($_attr[var],$_attr[value],false,$_nocache,$_scope);?>";
  54. }
  55. }
  56. }
  57. ?>