在一個新的Typo3安裝中,我有一個這樣的模板。現在如何將數組傳遞給FLUIDTEMPLATE?
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
file = fileadmin/default/templates/index.html
...
variables {
...
myPages = CONTENT
myPages {
table = pages
select {
pidInList = 76
orderBy = sorting
}
}
}
}
}
我想遍歷我fluidtemplate的網頁是這樣的:
<f:for each="{myPages}" as="page">
<f:format.raw>{page.title}</f:format.raw>
</f:for>
不幸的是,如果我做了一個 <f:debug title="debugger">{myPages}</f:debug>
它表明這是一個空字符串。
如何將我選擇的內容對象的結果數組傳遞給FLUIDTEMPLATE?
UPDATE:
我解決它創建一個自定義視圖助手,它返回一個給定的parentId頁的數組。結果存儲在流體變量中。在模板
class Tx_Custom_ViewHelpers_Pages_GetViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Gets subpages for a given page.
*
* @param int $parentId ID of the parentpage.
* @param string $target Target Variable
*/
public function render($parentId, $target='content') {
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages', 'pid=' . $parentId);
if ($this->templateVariableContainer->exists($target) === TRUE) {
$this->templateVariableContainer->remove($target);
}
$this->templateVariableContainer->add($target, $rows);
}
}
用法:
{namespace cn=Tx_Custom_ViewHelpers}
<cn:pages.get parentId="{parentId}" target="pages"/>
<f:for each="{pages}" as="p">
page: {p.title}
</f:for>
剩餘的TypoScript:
page = PAGE
page {
10 = FLUIDTEMPLATE
10{
file = fileadmin/default/templates/index.html
layoutRootPath = fileadmin/default/templates/layouts/
partialRootPath = fileadmin/default/templates/partials/
variables {
content < styles.content.get
parentId = TEXT
parentId.value = 76
}
}
}
內容對象不是一個數組...所以本雅明的答案意見適用。 – lorenz