Documentation · ViewHelper reference


Loop view helper which can be used to interate over array.
Implements what a basic foreach()-PHP-method does.


Simple Loop

<f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo">{foo}</f:for>



Output array key

    <f:for each="{fruit1: 'apple', fruit2: 'pear', fruit3: 'banana', fruit4: 'cherry'}" as="fruit" key="label">
  • {label}: {fruit}
  • </f:for>


  • fruit1: apple
  • fruit2: pear
  • fruit3: banana
  • fruit4: cherry

Iteration information

    <f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" iteration="fooIterator">
  • Index: {fooIterator.index} Cycle: {fooIterator.cycle} Total: {}{f:if(condition: fooIterator.isEven, then: ' Even')}{f:if(condition: fooIterator.isOdd, then: ' Odd')}{f:if(condition: fooIterator.isFirst, then: ' First')}{f:if(condition: fooIterator.isLast, then: ' Last')}
  • </f:for>


  • Index: 0 Cycle: 1 Total: 4 Odd First
  • Index: 1 Cycle: 2 Total: 4 Even
  • Index: 2 Cycle: 3 Total: 4 Odd
  • Index: 3 Cycle: 4 Total: 4 Even Last

  • Tag usage example

    <f:for each="{foo: 'bar'}" as="foo" key="''" reverse="1" iteration="NULL">
    	<!-- tag content - may be ignored! -->
  • Inline usage example

    {f:for(each: {foo: 'bar'}, as: 'foo', key: '''', reverse: 1, iteration: 'NULL')}


Argument Description Type

The name of the iteration variable


The array or \TYPO3\CMS\Extbase\Persistence\ObjectStorage to iterated over


The name of the variable to store iteration information (index, cycle, isFirst, isLast, isEven, isOdd)


The name of the variable to store the current array key


If enabled, the iterator will start with the last element and proceed reversely

Required attribute

Revision history

commit 3d8ce2a4c4dbad9bd23cc88fa5d9802b3f429374
Author: Sebastian Kurfürst <*****>
Date:   Thu Mar 26 11:38:42 2009 +0000

    Fluid: First backport

commit ddfaa33a031a759f497998bca5bdc581a85474b2
Author: Sebastian Kurfürst <*****>
Date:   Thu Mar 26 15:22:22 2009 +0000

    Fluid: Added automatic registration of arguments

commit 5525f95428c42216705860b600484adde9015a7f
Author: Christopher Hlubek <*****>
Date:   Sat Mar 28 16:54:46 2009 +0000

    Added a key argument to enable the usage of associative arrays in for

commit c94b14a3c5194441169de0d2e6e17b650a90337f
Author: Jochen Rau <*****>
Date:   Sat Mar 28 20:37:21 2009 +0000

    * Fixed problem with encoding of the url arguments
    * The link view helper now takes the controller argument into account

commit a68b28f9f8113d58a64b41f0897b6902b43ce200
Author: Sebastian Kurfürst <*****>
Date:   Sun Apr 12 06:55:08 2009 +0000

    * Cleaned up TypoScriptViewHelper
    * Cleaned up ForViewHelper

commit 38ebcedd944471b83d9293b648264fd3e65634f1
Author: Bastian Waidelich <*****>
Date:   Tue May 5 20:52:33 2009 +0000

    * Changes backported from FLOW3:
      * major cleanup and refactoring of core and view helper classes & comments
      * added validation for boolean arguments in AbstractViewHelper
      * added initialize-method to AbstractViewHelper, that is called before render(). This was especially needed for tagbased viewhelpers.
      * renderChildren() now directly calls evaluateChildNodes() on the respective view helper node allowing us to render objects/arrays.
      * improved boolean type conversion for arguments in ViewHelperNode.
      * added TagBuilder class, re-wrote all tag based view helpers to use it (see form view helpers for some examples)
      * ViewHelperArguments collection got a new method "hasArgument()" that returns TRUE when the specified argument exists and is not NULL
    * tx_fluid changes:
      * Improved fake object factory. Now objects are injected to subclasses and implementations of the specified classes/interfaces.
      * cleaned up and tweaked view helpers. Removed Parsefunc, Stdwrap and TypoScript view helpers for now. Added CObject, If/Then/Else, EmailLink, Crop, Currency, Debug, HTML, Nl2br, Image view helpers. Thanks to Sebastian Böttger, Christopher Hlubek, Niels Pardon, Andreas Pattynama for the help!
    * Note: Unit tests not fully backported yet.

commit 50af6b9c08d04e3e1d4ce56a499a9a3d4b84efc3
Author: Sebastian Kurfürst <*****>
Date:   Thu May 28 21:45:46 2009 +0000

    * Backported major changes from Fluid v5 to Fluid v4
    * !!! Many of these changes are not backwards-compatible! Please read this if you have written custom ViewHelpers!
    * Introduced Shorthand Syntax for calling ViewHelpers
    * Core:
    ** Lots of internal cleanup and refactorings.
    ** !!! Complete restructuring into subpackages.
    * ViewHelpers:
    ** !!! The base classes of ViewHelpers changed to Tx_Fluid_Core_ViewHelper_AbstractViewHelper and Tx_Fluid_Core_ViewHelper_TagBasedViewHelper. Please adjust your ViewHelpers!
    ** !!! $this->variableContainer has been renamed to $this->templateVariableContainer
    ** !!! the view is not in $this->variableContainer anymore. Currently there is no way to fetch the View from a ViewHelper.
    ** Introduced a new $this->controllerContext containing the context variables of the controller
    ** !!! The request can be now found in $this->controllerContext->getRequest()
    ** !!! The URIHelper has been renamed to URIBuilder and can be now found in $this->controllerContext->getURIBuilder()
    ** Introduced a new ViewHelperVariableContainer, available in $this->viewHelperVariableContainer to pass data between ViewHelpers. Should only be needed in very rare cases.
    ** !!! Removed <f:format.htmlEscape> ViewHelper! Please remove these declarations in your template! Escaping of object accessors is now automatically done, see next point.
    * !!! ObjectAccessors {...} are now automatically HTMLspecialChar'd if not used as an argument to a ViewHelper. This is done using a new ObjectAccessorPostProcessor. Lateron, this will be made configurable.

commit 50af2479b72ce04ea9efb888da68873b990a08df
Author: Sebastian Kurfürst <*****>
Date:   Mon Aug 3 07:30:07 2009 +0000

    [~TASK] Fluid: R*****@internal annotations and added @api annotations
    [~TASK] Fluid: Now, one ViewHelperNode only ever uses one instance of a ViewHelper

commit dca2931ee01d1e0ca5f3277b0dd2cde52706cafd
Author: Bastian Waidelich <*****>
Date:   Wed Sep 16 16:52:53 2009 +0000

    [~TASK] Fluid: tweaked exception that is thrown when trying to iterate through non-traversable objects in ForViewHelper
    [~TASK] Fluid: fixed typo in ForViewHelperTest
    [+FEATURE] Fluid: added CycleViewHelper. Resolves #4458
    [+FEATURE] Fluid: added GroupedForViewHelper. Resolves #4460
    [+TASK] Fluid: added test case for PaddingViewHelper. Relates to #4459

commit c48ae2617d031f739733a1a89908a8ca1ab889a1
Author: Sebastian Kurfürst <*****>
Date:   Fri Oct 9 14:57:20 2009 +0000

    [TASK] tx_fluid: Backported some non-functional changes

commit 9b2830bc1c17588dd69a463773c5f05f61b5cf94
Author: Sebastian Kurfürst <*****>
Date:   Sat Oct 24 11:01:38 2009 +0000

    * A*****@api annotations
    * Changed the fluid-specific RuntimeException to SPL's RuntimeException.

commit 7868047c52417ff4e1f3e99e45adaba1ee3d0a24
Author: Sebastian Kurfürst <*****>
Date:   Sat Oct 24 11:49:45 2009 +0000

    [~TASK] Fluid: A*****@package and @subpackage annotations.

commit 06372a84a645147029501d2b2b06a4fdfe56b7d7
Author: Michael Stucki <*****>
Date:   Wed Nov 25 21:53:57 2009 +0000

    Add missing SVN properties for new or modified files

commit ed19fe9e4a6d2e91c594784adea24aa82064dd47
Author: Sebastian Kurfürst <*****>
Date:   Mon Jul 12 20:18:26 2010 +0000

    Fluid in v5 and v4 are now synchronized again!
    [+FEATURE] Fluid: The TemplateVariableContainer now provides a method to retrieve all variables.
    [~TASK] Fluid (Core): Introduced a RenderingContextInterface to more cleanly decouple Fluid's rendering context from the TypoScript rendering context. Note that view helpers (and other code) should now refer to that interface instead of the concrete Fluid implementation!
    [!!!][+BUGFIX] Fluid (Core): Refactored all Condition-ViewHelpers like f:if, f:security.if* to use a newly created base class F3\Fluid\Core\ViewHelper\ConditionViewHelper. This greatly simplifies the implementation of custom conditions. However, THIS IS A BREAKING CHANGE in case you copied the f:if ViewHelper to create a custom condition ViewHelper, as the internal workings changed. Please check the new f:if ViewHelper to see how to adjust your ViewHelper -- you basically just have to throw away a lot of code. Resolves #8824.
    [!!!][-API] Fluid (TemplateView): Removed renderSection() and renderWithLayout() from public API in Tx_Fluid_View_TemplateView, as this should only be called from inside Fluid.
    [!!!][TASK] Fluid (ViewHelpers): the <f:section />-ViewHelper now does NOT render itself anymore when encountered in a normal template. Example: Before the change, the template "before <f:section name='...'> middle </f:section> after" was rendered as "before middle after", but now it is only rendered as "before after". Although this is a breaking change, it is quite unlikely that anybody relied on this behavior, as it was inconsistent beforehand.
    [TASK] Fluid (TemplateView): Major refactoring of the layout, partial and section rendering mechanism. This also induces a speedup as retundant rendering is eliminated.
    [+FEATURE] Fluid (ViewHelpers): The <f:render>-ViewHelper can be now used to render sections in the same partial and template. In these cases, all arguments need to be specified explicitely. Additionally, it can now be used to render a section recursively.
    [~TASK] Fluid (Core): Removed some non-API-methods which were never called.

commit 186bdaeac89820779f91853b830cc95d60c7ad58
Author: Bastian Waidelich <*****>
Date:   Tue Jul 13 09:42:26 2010 +0000

    [-TASK] Fluid: R*****@version annotation from all Fluid classes to ease the backporting process. Relates to #8835 (backported from Fluid package)

commit 1d36de6ed90007e324b773782e8f0a1d1c1191a2
Author: Bastian Waidelich <*****>
Date:   Tue Jul 13 10:12:30 2010 +0000

    [-TASK] Fluid: R*****@package/@subpackage annotations from all Fluid classes. They have already been removed in FLOW3 packages in r2813.

commit 2bd9f56a7a820e303cc9ad9900557edb677136a8
Author: Bastian Waidelich <*****>
Date:   Tue Jul 13 14:17:07 2010 +0000

    [+BUGFIX] Fluid: Replaced SplObjectStorage by Tx_Extbase_Persistence_ObjectStorage to be PHP 5.2-compatible (which ships with a broken implementation of SplObjectStorage)
    [!!!][~TASK] Fluid (Core): Renamed ConditionViewHelper and TagBasedViewHelper to Abstract*ViewHelper as per CGL. (backported from Fluid package r4840). To be backwards-compatible, TagBasedViewHelper.php still exists and will write an entry to TYPO3s deprecation log if used. Please adapt your custom ViewHelpers and inherit from AbstractTagBasedViewHelper instead of TagBasedViewHelper. This resolves #8834
    [~TASK] Fluid: Marked vfs unit tests to be skipped, as vfs is not part of v4 (yet)

commit 308ba1732bf519a8459cb939d77d0bdc4aaf9735
Author: Bastian Waidelich <*****>
Date:   Thu Jul 22 14:47:59 2010 +0000

    [~TASK] Fluid (ViewHelpers): Replaced custom convertToArray() method by PHPs iterator_to_array() function in cycle, for and groupedFor ViewHelpers. This resolves #8732. (backport from Fluid package r4898)

commit 50071e362b9e96ceddcafef46eebe5b86cf8cbce
Author: Bastian Waidelich <*****>
Date:   Mon Jul 26 11:04:42 2010 +0000

    [+FEATURE] Fluid (ViewHelpers): Added iteration information to for ViewHelper. Thanks to all the contributors for your input and patches! This resolves #6149 (backported from Fluid package r4904)

commit ac250c45d5cbd8bf450900f8d6e39f34344f9056
Author: Bastian Waidelich <*****>
Date:   Mon Jul 26 15:11:22 2010 +0000

    [~TASK] Fluid (Tests): committing modified AbstractFormFieldViewHelperTest that I forgot to add in previous commit
    [+TASK] Fluid (ViewHelpers): Small performance improvement in ForViewHelper: Objects will only be converted to arrays if reverse is TRUE. Relates to #8732 (backported from Fluid package r4907)
    [+TASK] Fluid (View): Added getter for template parser to AbstractTemplateView. This is useful if you want to use the parser from within your custom ViewHelper (creating a new instance would skip interceptor registration) (backported from Fluid package r4907)

commit 472451987ca0530fa5828bb0b79fcafa2f905a35
Author: Bastian Waidelich <*****>
Date:   Fri Nov 19 20:58:09 2010 +0000

    [-TASK] Fluid: R*****@scope annotations as they are not used in v4

commit b3637985e7ebb34dd12d6181b214ae5ce4b70f54
Author: Bastian Waidelich <*****>
Date:   Thu Jul 28 17:01:44 2011 +0200

    [!!!][FEATURE] Compilation of Fluid templates to PHP files
    This adds a compile step to the parsing process of templates, layouts and
    If no compiled cache file exists, Fluid will create it while parsing the
    respective Fluid template.
    The cache file is invalidated as soon as the template/layout/partial
    has been modified (or if caches are flushed).
    This speeds up the rendering process by factor 2-5!
    Breaking change:
    * AbstractViewHelper::$arguments are no longer an object but an array.
      If you used $this->arguments->hasArgument() in your custom ViewHelpers,
      you'll have to replace this with $this->hasArgument()
    Change-Id: Idb71f85ea7223755df4bc1c0ff9f8807f1924323
    Related: #28544
    Resolves: #28545

commit fd09d197fa8886b97cb20aa9573f39cd08ce989e
Author: Bastian Waidelich <*****>
Date:   Thu Nov 10 18:27:58 2011 +0100

    [TASK] S*****@author annotations
    This backports three recent changes of the TYPO3.Fluid package:
    - R*****@license annotation from files (290f4f5)
    - Simplify license header in PHP files (14bacba)
    - D*****@author tags from source code (9c2e837)
    This should not contain any functional change!
    Change-Id: I9376dca4af78c4f0f82413011d115b8ad04634dd

commit ca40f8a066da4ea3c849d74f68a9bc73758976c5
Author: dkd-egerer Sascha Egerer <*****>
Date:   Sat Apr 14 21:43:10 2012 +0200

    [TASK] Remove trailing whitespace
    There must be no empty lines after the closing
    PHP tag. Empty lines after closing tags break
    output compression in PHP and/or result in AJAX
    Change-Id: I0484ca29d8134d0828cf30880d5aafd43ed9d78e
    Resolves: #36076
    Releases: 6.0
    Reviewed-by: Ingo Pfennigstorf
    Tested-by: Ingo Pfennigstorf
    Reviewed-by: Daniel Lorenz
    Tested-by: Daniel Lorenz
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn

commit ec3891d8d4e339d8319428211207e6201be9fd73
Author: Thomas Maroschik <*****>
Date:   Wed Oct 17 21:18:26 2012 +0200

    [TASK][WIP] Move non class code back to source files
    Change-Id: I620d2e61860142cdc89cc83474c95542799961c0

commit 554e8f890dcc0dd86a27518b58e2b54be26fd37e
Author: Thomas Maroschik <*****>
Date:   Wed Oct 17 22:20:17 2012 +0200

    [TASK] Namespace classes
    Change-Id: Ia7432e1c923826ed58206bca15fb94509adbd508

commit e9994c26660d759d02271b0308634a5350f45bdb
Author: Helmut Hummel <*****>
Date:   Wed Oct 31 12:16:50 2012 +0100

    [TASK] Replace old class names with namespaced ones
    Releases: 6.0
    Change-Id: I10badfae2aeff003e47df099e79accd9be6bd678
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit c06b495891bd86d564c590bc15c517ac47683b69
Author: Helmut Hummel <*****>
Date:   Wed Oct 31 21:15:58 2012 +0100

    [BUGFIX] Replace GenericObjectStorage in Fluid
    Change-Id: I60161676e457c20b14bcba3491a4d41b3c83073a
    Releases: 6.0
    Fixes: #42554
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit 9d13dedf017b614b834261b1bf5d4acb2201f1d4
Author: Alexander Schnitzler <*****>
Date:   Fri Nov 16 19:49:02 2012 +0100

    [CLEANUP] Replace FLOW3 with TYPO3 Flow
    Releases: 6.0
    Fixes: #43036
    Change-Id: I62df23587301b4cde3ddeae3686b34f54fe1182e
    Reviewed-by: Alexander Schnitzler
    Tested-by: Alexander Schnitzler

commit 9d46e6932d35c79bf87c96fa38b8e537c4192f23
Author: Alexander Schnitzler <*****>
Date:   Tue Nov 20 16:27:02 2012 +0100

    [CLEANUP] Adjust code to CGL and fix small namespace bugs
    * whitespaces, tabs and blank line issues
    * bool -> boolean
    * int -> integer
    * fix wrong namespace annotations
    Fixes: #43157
    Releases: 6.0
    Change-Id: I8397948e19248db029d8efd1555ee56e4982742d
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit 50d433bbde06b4b9eab146caea64d09239949e64
Author: Tymoteusz Motylewski <*****>
Date:   Sun Mar 3 18:53:42 2013 +0100

    [TASK] Sync CMS Fluid with Flow Fluid 1.1 (part2)
    This is the second part of a backport fluid from Flow.
    Change-Id: I96e47131414c50801ff7628508dc05d7d7b5e106
    Releases: 6.1
    Resolves: #44819
    Fixes: #45985
    Reviewed-by: Wouter Wolters
    Tested-by: Wouter Wolters
    Reviewed-by: Marc Bastian Heinrichs
    Tested-by: Marc Bastian Heinrichs

commit 77f29a3c69a7cbb27b34072754aa503bace6c9f1
Author: Christian Kuhn <*****>
Date:   Tue Oct 1 14:40:56 2013 +0200

    [TASK] Remove closing PHP tags
    Change-Id: Iaa92566c53301e49396fc9fb26b0b339c48d567b
    Resolves: #52360
    Releases: 6.2
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Ernesto Baschny
    Tested-by: Ernesto Baschny
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring