首页 文章

如何将数组传递给FLUIDTEMPLATE?

提问于
浏览
1

在一个新的Typo3安装我有一个这样的模板 .

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:

我解决了它创建自定义viewhelper,它返回给定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>

其余的错字:

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
        }
    }

}

1 回答

相关问题