在TYPO3中每个第n个列表元素之后添加PHP扩展代码


Adding PHP code in extension after every nth list element in TYPO3

我使用老式的方式(kickstarter)来构建TYPO3的扩展。我想添加一些PHP代码后的第三个元素的列表,但我真的不知道如何做到这一点。

我的代码是这样的:

protected function makeList($res) {
    $items = array();
        // Make list table rows
    while (($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
        $items[] = $this->makeListItem();
    }
    $out = '<div' . $this->pi_classParam('listrow') . '>list items</div>';
    return $out;
}

:

protected function makeListItem() {
    $out = 'list item details';
    return $out;
}

如果我理解正确的话,您需要这样做:

protected function makeList($res) {
    $items = array();
    // Make list table rows
    $i = 0;
    $out = '<div' . $this->pi_classParam('listrow') . '>';
    while (($this->internal['currentRow'] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
        $out .= $this->makeListItem();
        $i++;
        if ($i == 3) {
             $out .= '<img src="whateverjpg">';
             $i = 0; // if you want to do it every 3 images
        }            
    }

    $out .= '</div>';
    return $out;
}