gehe zur Dokumentation dieser Datei
50 public function compile($args, $compiler, $parameter)
55 $from = $_attr[
'from'];
56 $item = $_attr[
'item'];
57 if (!strncmp(
"\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) {
58 $compiler->trigger_template_error(
"item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno);
61 if (isset($_attr[
'key'])) {
67 $this->
openTag($compiler,
'foreach', array(
'foreach', $compiler->nocache, $item, $key,
true));
69 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
71 if (isset($_attr[
'name'])) {
72 $name = trim($_attr[
'name'],
'\'"');
74 $SmartyVarName = "\$smarty.foreach.{$name}.
";
78 $ItemVarName = '$' . trim($item, '\'"') . '@
';
79 // evaluates which Smarty variables and properties have to be computed
82 $useSmartyForeach = $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first
') !== false;
83 $useSmartyForeach = ($usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last
') !== false) || $useSmartyForeach;
84 $useSmartyForeach = ($usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index
') !== false) || $useSmartyForeach;
85 $useSmartyForeach = ($usesSmartyIteration = (!$usesSmartyIndex && ($usesSmartyFirst || $usesSmartyLast)) || strpos($compiler->lex->data, $SmartyVarName . 'iteration
') !== false) || $useSmartyForeach;
86 $useSmartyForeach = ($usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show
') !== false) || $useSmartyForeach;
87 $useSmartyForeach = ($usesSmartyTotal = $usesSmartyLast ||strpos($compiler->lex->data, $SmartyVarName . 'total
') !== false) || $useSmartyForeach;
89 $usesSmartyFirst = false;
90 $usesSmartyLast = false;
91 $usesSmartyTotal = false;
92 $usesSmartyShow = false;
93 $useSmartyForeach = false;
96 $usesPropKey = strpos($compiler->lex->data, $ItemVarName . 'key
') !== false;
97 $usesPropFirst = strpos($compiler->lex->data, $ItemVarName . 'first
') !== false;
98 $usesPropLast = strpos($compiler->lex->data, $ItemVarName . 'last
') !== false;
99 $usesPropIndex = strpos($compiler->lex->data, $ItemVarName . 'index
') !== false;
100 $usesPropIteration = (!$usesPropIndex && ($usesPropFirst || $usesPropLast)) || strpos($compiler->lex->data, $ItemVarName . 'iteration
') !== false;
101 $usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show
') !== false;
102 $usesPropTotal = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total
') !== false;
106 $keyTerm = "\$_smarty_tpl->tpl_vars[$item]->key => ";
107 } elseif ($key != null) {
108 $keyTerm = "\$_smarty_tpl->tpl_vars[$key]->value => ";
110 // generate output code
112 $output .= "\$_from = $from;\n";
113 $output .= "if (!is_array(\$_from) && !is_object(\$_from)) {\n";
114 $output .= "settype(\$_from, 'array
');\n";
116 $output .= "\$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n";
117 $output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = false;\n";
119 $output .= "\$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n";
121 if ($usesPropTotal) {
122 $output .= "\$_smarty_tpl->tpl_vars[$item]->total= \$_smarty_tpl->_count(\$_from);\n";
124 if ($usesPropIteration) {
125 $output .= "\$_smarty_tpl->tpl_vars[$item]->iteration=0;\n";
127 if ($usesPropIndex) {
128 $output .= "\$_smarty_tpl->tpl_vars[$item]->index=-1;\n";
131 if ($usesPropTotal) {
132 $output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->tpl_vars[$item]->total > 0);\n";
134 $output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->_count(\$_from) > 0);\n";
139 if ($usesSmartyTotal) {
140 $prop['total
'] = "'total
' => ";
141 $prop['total
'] .= $usesSmartyShow ? '$total =
' : '';
142 $prop['total
'] .= '$_smarty_tpl->_count($_from)
';
144 if ($usesSmartyIteration) {
145 $prop['iteration
'] = "'iteration
' => 0";
147 if ($usesSmartyIndex) {
148 $prop['index
'] = "'index
' => -1";
150 if ($usesSmartyShow) {
151 $prop['show
'] = "'show
' => ";
152 if ($usesSmartyTotal) {
153 $prop['show
'] .= "(\$total > 0)";
155 $prop['show
'] .= "(\$_smarty_tpl->_count(\$_from) > 0)";
158 if ($useSmartyForeach) {
159 $_vars = 'array(
' . join(',
', $prop) . ')
';
160 $foreachVar = "'__foreach_{$name}
'";
161 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar] = new Smarty_Variable({$_vars});\n";
164 $output .= "foreach (\$_from as {$keyTerm}\$_smarty_tpl->tpl_vars[$item]->value) {\n";
165 $output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n";
166 if ($key != null && $usesPropKey) {
167 $output .= "\$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n";
169 if ($usesPropIteration) {
170 $output .= "\$_smarty_tpl->tpl_vars[$item]->iteration++;\n";
172 if ($usesPropIndex) {
173 $output .= "\$_smarty_tpl->tpl_vars[$item]->index++;\n";
175 if ($usesPropFirst) {
176 if ($usesPropIndex) {
177 $output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index == 0;\n";
179 $output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->iteration == 1;\n";
183 if ($usesPropIndex) {
184 $output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->index + 1 == \$_smarty_tpl->tpl_vars[$item]->total;\n";
186 $output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration == \$_smarty_tpl->tpl_vars[$item]->total;\n";
190 if ($usesSmartyIteration) {
191 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration
']++;\n";
193 if ($usesSmartyIndex) {
194 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['index
']++;\n";
196 if ($usesSmartyFirst) {
197 if ($usesSmartyIndex) {
198 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first
'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index
'] == 0;\n";
200 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first
'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration
'] == 1;\n";
203 if ($usesSmartyLast) {
204 if ($usesSmartyIndex) {
205 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last
'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index
'] + 1 == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total
'];\n";
207 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last
'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration
'] == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total
'];\n";
211 $itemName = trim($item,"'\
"");
212 $output .=
"\$foreach_{$itemName}_Sav = \$_smarty_tpl->tpl_vars[$item];\n";
236 public function compile($args, $compiler, $parameter)
241 list($openTag, $nocache, $item, $key, $foo) = $this->
closeTag($compiler, array(
'foreach'));
242 $this->
openTag($compiler,
'foreachelse', array(
'foreachelse', $nocache, $item, $key,
false));
243 $itemName = trim($item,
"'\"");
245 $output .=
"\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n";
247 $output .=
"if (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
269 public function compile($args, $compiler, $parameter)
274 if ($compiler->nocache) {
275 $compiler->tag_nocache =
true;
278 list($openTag, $compiler->nocache, $item, $key, $restore) = $this->
closeTag($compiler, array(
'foreach',
'foreachelse'));
279 $itemName = trim($item,
"'\"");
282 $output .=
"\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n";
Sie sind hier: Home » MyOOS Benutzerhandbuch » Smarty
Korrekturen, Hinweise und Ergänzungen
Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag
Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.