FluidTYPO3\Vhs\ViewHelpers\Iterator\ChunkViewHelper::render PHP Method

render() public method

Render method
public render ( integer $count, boolean $fixed = false, boolean $preserveKeys = false ) : array
$count integer The count of items per chunk or if fixed number of chunks
$fixed boolean Whether to allocate items to a fixed number of chunks or not
$preserveKeys boolean If set to true, the original array keys will be preserved in the chunks
return array
    public function render($count, $fixed = false, $preserveKeys = false)
    {
        $subject = $this->getArgumentFromArgumentsOrTagContentAndConvertToArray('subject');
        $output = [];
        if (0 >= $count) {
            return $output;
        }
        if (true === (bool) $fixed) {
            $subjectSize = count($subject);
            if (0 < $subjectSize) {
                $chunkSize = ceil($subjectSize / $count);
                $output = array_chunk($subject, $chunkSize, $preserveKeys);
            }
            // Fill the resulting array with empty items to get the desired element count
            $elementCount = count($output);
            if ($elementCount < $count) {
                $output += array_fill($elementCount, $count - $elementCount, null);
            }
        } else {
            $output = array_chunk($subject, $count, $preserveKeys);
        }
        return $this->renderChildrenWithVariableOrReturnInput($output);
    }