2014-03-24 72 views
0

我使用老式时尚方式(kickstarter)在TYPO3中构建扩展。我想在列表的第三个元素后面添加一些PHP代码,但是我真的不知道如何执行此操作。在TYPO3中的每第n个列表元素之后添加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; 
} 

回答

0

如果我理解正确的话,你就需要这样的事:

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; 
} 
+0

此代码插入'PHP代码“在页面顶部(源代码之前) – Adrian

+0

如果你想要打印的东西像html,如果你添加这个逻辑到视图(因为它看起来像是视图逻辑)。 实际上,您可以将所有逻辑移动到视图,并将$ items传递给视图。 也许我不明白你想达到什么,所以如果你给我更多的信息,我可能会更好地帮助你。 :) –

+0

元素的扩展生成列表,我想在第n个列表项后面插入图像。 – Adrian

相关问题