3 * Smarty Internal Plugin Compile Capture
4 * Compiles the {capture} tag
12 * Smarty Internal Plugin Compile Capture Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
20 * Attribute definition: Overwrites base class.
23 * @see Smarty_Internal_CompileBase
25 public $shorttag_order = array('name');
28 * Attribute definition: Overwrites base class.
31 * @see Smarty_Internal_CompileBase
33 public $optional_attributes = array('name', 'assign', 'append');
36 * Compiles code for the {$smarty.capture.xxx}
38 * @param array $args array with attributes from parser
39 * @param \Smarty_Internal_TemplateCompilerBase$compiler compiler object
40 * @param array $parameter array with compilation parameter
42 * @return string compiled code
43 * @throws \SmartyCompilerException
45 public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
47 $tag = trim($parameter[ 0 ], '"\'');
48 $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
50 $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
52 return "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')";
56 * Compiles code for the {capture} tag
58 * @param array $args array with attributes from parser
59 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
60 * @param null $parameter
62 * @return string compiled code
64 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
66 // check and get attributes
67 $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
69 $buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
70 $assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
71 $append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
73 $compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
74 // maybe nocache because of nocache variables
75 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
76 $_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
83 * Smarty Internal Plugin Compile Captureclose Class
86 * @subpackage Compiler
88 class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
91 * Compiles code for the {/capture} tag
93 * @param array $args array with attributes from parser
94 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
95 * @param null $parameter
97 * @return string compiled code
99 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
101 // check and get attributes
102 $_attr = $this->getAttributes($compiler, $args, $parameter, '/capture');
103 // must endblock be nocache?
104 if ($compiler->nocache) {
105 $compiler->tag_nocache = true;
108 list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
110 return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>";