smarty_internal_compile_while.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile While
  4. *
  5. * Compiles the {while} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile While Class
  13. */
  14. class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the {while} 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('if condition');
  26. // check and get attributes
  27. $_attr = $this->_get_attributes($args);
  28. $this->_open_tag('while', $this->compiler->nocache);
  29. // maybe nocache because of nocache variables
  30. $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
  31. if (is_array($args['if condition'])) {
  32. $_output = " <?php if (!isset(\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."])) \$_smarty_tpl->tpl_vars[".$args['if condition']['var']."] = new Smarty_Variable;\n";
  33. $_output .= " while (\$_smarty_tpl->tpl_vars[".$args['if condition']['var']."]->value = ".$args['if condition']['value'].") {\n ?>";
  34. return $_output;
  35. } else {
  36. return '<?php while (' . $args['if condition'] . ') { ?>';
  37. }
  38. }
  39. }
  40. /**
  41. * Smarty Internal Plugin Compile Whileclose Class
  42. */
  43. class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase {
  44. /**
  45. * Compiles code for the {/while} tag
  46. *
  47. * @param array $args array with attributes from parser
  48. * @param object $compiler compiler object
  49. * @return string compiled code
  50. */
  51. public function compile($args, $compiler)
  52. {
  53. $this->compiler = $compiler;
  54. // must endblock be nocache?
  55. if ($this->compiler->nocache) {
  56. $this->compiler->tag_nocache = true;
  57. }
  58. $this->compiler->nocache = $this->_close_tag(array('while'));
  59. return "<?php }?>";
  60. }
  61. }
  62. ?>