Fluid:
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / ForViewHelper.php
1 <?php
2
3 /* *
4 * This script is part of the TYPO3 project - inspiring people to share! *
5 * *
6 * TYPO3 is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License version 2 as published by *
8 * the Free Software Foundation. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13 * Public License for more details. *
14 * */
15
16 /**
17 * @package Fluid
18 * @subpackage ViewHelpers
19 * @version $Id: ForViewHelper.php 1962 2009-03-03 12:10:41Z k-fish $
20 */
21
22 /**
23 * Loop view helper
24 *
25 * @package Fluid
26 * @subpackage ViewHelpers
27 * @version $Id: ForViewHelper.php 1962 2009-03-03 12:10:41Z k-fish $
28 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
29 * @scope prototype
30 */
31 class Tx_Fluid_ViewHelpers_ForViewHelper extends Tx_Fluid_Core_AbstractViewHelper {
32 /**
33 * Render.
34 *
35 * @param array $each The array to be iterated over
36 * @param string $as The name of the iteration variable
37 * @param string $key The name of the variable to store the current array key
38 * @return string Rendered string
39 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
40 */
41 public function render($each, $as, $key = '') {
42 $out = '';
43 if (!empty($each)) {
44 foreach ($each as $keyValue => $singleElement) {
45 $this->variableContainer->add($as, $singleElement);
46 if (strlen($key)) {
47 $this->variableContainer->add($key, $keyValue);
48 }
49 $out .= $this->renderChildren();
50 $this->variableContainer->remove($as);
51 if (strlen($key)) {
52 $this->variableContainer->remove($key);
53 }
54 }
55 }
56 return $out;
57 }
58 }
59
60 ?>