TYPO3 CMS  TYPO3_6-2
TYPO3\CMS\Fluid\ViewHelpers\GroupedForViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\ViewHelpers\GroupedForViewHelper:
TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper Tx_Fluid_ViewHelpers_GroupedForViewHelper

Public Member Functions

 render ($each, $as, $groupBy, $groupKey='groupKey')
 
- Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 setArguments (array $arguments)
 
 setRenderingContext (\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
 isEscapingInterceptorEnabled ()
 
 setViewHelperNode (\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode $node)
 
 setRenderChildrenClosure (\Closure $renderChildrenClosure)
 
 initializeArgumentsAndRender ()
 
 initialize ()
 
 renderChildren ()
 
 prepareArguments ()
 
 validateArguments ()
 
 initializeArguments ()
 
 compile ($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
 
 resetState ()
 

Protected Member Functions

 groupElements (array $elements, $groupBy)
 
- Protected Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 registerArgument ($name, $type, $description, $required=FALSE, $defaultValue=NULL)
 
 overrideArgument ($name, $type, $description, $required=FALSE, $defaultValue=NULL)
 
 callRenderMethod ()
 
 buildRenderChildrenClosure ()
 
 hasArgument ($argumentName)
 

Additional Inherited Members

- Static Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
static renderStatic (array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
- Protected Attributes inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 $arguments
 
 $templateVariableContainer
 
 $controllerContext
 
 $renderingContext
 
 $renderChildrenClosure = NULL
 
 $viewHelperVariableContainer
 
 $objectManager
 
 $escapingInterceptorEnabled = TRUE
 

Detailed Description

Grouped loop view helper. Loops through the specified values.

The groupBy argument also supports property paths.

= Examples =

<f:groupedFor each="{0: {name: 'apple', color: 'green'}, 1: {name: 'cherry', color: 'red'}, 2: {name: 'banana', color: 'yellow'}, 3: {name: 'strawberry', color: 'red'}}" as="fruitsOfThisColor" groupBy="color"> <f:for each="{fruitsOfThisColor}" as="fruit"> {fruit.name} </f:for> </f:groupedFor> <output> apple cherry strawberry banana </output>

f:groupedFor each="{0: {name: 'apple', color: 'green'}, 1: {name: 'cherry', color: 'red'}, 2: {name: 'banana', color: 'yellow'}, 3: {name: 'strawberry', color: 'red'}}" as="fruitsOfThisColor" groupBy="color" groupKey="color"> {color} fruits:

f:for each="{fruitsOfThisColor}" as="fruit" key="label"> {label}: {fruit.name} </f:for> </f:groupedFor> <output>

  • green fruits
    • 0: apple
  • red fruits
    • 1: cherry
    • 3: strawberry
  • yellow fruits
    • 2: banana

</output>

Definition at line 72 of file GroupedForViewHelper.php.

Member Function Documentation

◆ groupElements()

TYPO3\CMS\Fluid\ViewHelpers\GroupedForViewHelper::groupElements ( array  $elements,
  $groupBy 
)
protected

Groups the given array by the specified groupBy property.

Parameters
array$elementsThe array / traversable object to be grouped
string$groupByGroup by this property
Returns
array The grouped array in the form array('keys' => array('key1' => [key1value], 'key2' => [key2value], ...), 'values' => array('key1' => array([key1value] => [element1]), ...), ...)
Exceptions

Definition at line 117 of file GroupedForViewHelper.php.

References TYPO3\CMS\Extbase\Reflection\ObjectAccess\getPropertyPath().

Referenced by TYPO3\CMS\Fluid\ViewHelpers\GroupedForViewHelper\render().

◆ render()

TYPO3\CMS\Fluid\ViewHelpers\GroupedForViewHelper::render (   $each,
  $as,
  $groupBy,
  $groupKey = 'groupKey' 
)

Iterates through elements of $each and renders child nodes

Parameters
array$eachThe array or to iterated over
string$asThe name of the iteration variable
string$groupByGroup by this property
string$groupKeyThe name of the variable to store the current group
Returns
string Rendered string
Exceptions

Definition at line 85 of file GroupedForViewHelper.php.

References TYPO3\CMS\Fluid\ViewHelpers\GroupedForViewHelper\groupElements(), and TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\renderChildren().