smarty_internal_compile_eval.php 1.4 KB

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