3 * Smarty Internal Plugin Compile While
4 * Compiles the {while} tag
12 * Smarty Internal Plugin Compile While Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
20 * Compiles code for the {while} tag
22 * @param array $args array with attributes from parser
23 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
24 * @param array $parameter array with compilation parameter
26 * @return string compiled code
27 * @throws \SmartyCompilerException
29 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
31 $compiler->loopNesting ++;
32 // check and get attributes
33 $_attr = $this->getAttributes($compiler, $args);
34 $this->openTag($compiler, 'while', $compiler->nocache);
36 if (!array_key_exists("if condition", $parameter)) {
37 $compiler->trigger_template_error("missing while condition", null, true);
40 // maybe nocache because of nocache variables
41 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
42 if (is_array($parameter[ 'if condition' ])) {
43 if ($compiler->nocache) {
44 // create nocache var to make it know for further compiling
45 if (is_array($parameter[ 'if condition' ][ 'var' ])) {
46 $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
48 $var = $parameter[ 'if condition' ][ 'var' ];
50 $compiler->setNocacheInVariable($var);
52 $prefixVar = $compiler->getNewPrefixVariable();
53 $assignCompiler = new Smarty_Internal_Compile_Assign();
54 $assignAttr = array();
55 $assignAttr[][ 'value' ] = "{$prefixVar}";
56 if (is_array($parameter[ 'if condition' ][ 'var' ])) {
57 $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
58 $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
59 $_output .= $assignCompiler->compile($assignAttr, $compiler,
60 array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
62 $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
63 $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
64 $_output .= $assignCompiler->compile($assignAttr, $compiler, array());
69 return "<?php\n while ({$parameter['if condition']}) {?>";
75 * Smarty Internal Plugin Compile Whileclose Class
78 * @subpackage Compiler
80 class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
83 * Compiles code for the {/while} tag
85 * @param array $args array with attributes from parser
86 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
88 * @return string compiled code
90 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
92 $compiler->loopNesting --;
93 // must endblock be nocache?
94 if ($compiler->nocache) {
95 $compiler->tag_nocache = true;
97 $compiler->nocache = $this->closeTag($compiler, array('while'));