3 * Smarty Internal Plugin Compile Capture
5 * Compiles the {capture} tag
13 * Smarty Internal Plugin Compile Capture Class
15 class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $shorttag_order = array('name');
18 public $optional_attributes = array('name', 'assign', 'append');
21 * Compiles code for the {capture} tag
23 * @param array $args array with attributes from parser
24 * @param object $compiler compiler object
25 * @return string compiled code
27 public function compile($args, $compiler)
29 $this->compiler = $compiler;
30 // check and get attributes
31 $_attr = $this->_get_attributes($args);
33 $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
34 $assign = isset($_attr['assign']) ? $_attr['assign'] : null;
35 $append = isset($_attr['append']) ? $_attr['append'] : null;
37 $this->compiler->_capture_stack[] = array($buffer, $assign, $append, $this->compiler->nocache);
38 // maybe nocache because of nocache variables
39 $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
40 $_output = "<?php ob_start(); ?>";
47 * Smarty Internal Plugin Compile Captureclose Class
49 class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
51 * Compiles code for the {/capture} tag
53 * @param array $args array with attributes from parser
54 * @param object $compiler compiler object
55 * @return string compiled code
57 public function compile($args, $compiler)
59 $this->compiler = $compiler;
60 // check and get attributes
61 $_attr = $this->_get_attributes($args);
62 // must endblock be nocache?
63 if ($this->compiler->nocache) {
64 $this->compiler->tag_nocache = true;
67 list($buffer, $assign, $append, $this->compiler->nocache) = array_pop($this->compiler->_capture_stack);
71 $_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());";
74 $_output .= " \$_smarty_tpl->append($append, ob_get_contents());";
76 $_output .= " Smarty::\$_smarty_vars['capture'][$buffer]=ob_get_clean();?>";