Typo3 打字稿在流体模板中的最佳用途是什么?
如果我想在流体模板中使用类似打字脚本的菜单生成,我有两种可能的方法:Typo3 打字稿在流体模板中的最佳用途是什么?,typo3,typoscript,fluid,Typo3,Typoscript,Fluid,如果我想在流体模板中使用类似打字脚本的菜单生成,我有两种可能的方法: 使用打字脚本为模板填充变量。这样做: page.10 = FLUIDTEMPLATE page.10 { templateName = index.html // ... define pathes ... variables { contentMain < styles.content.get mainMenu < temp.mainMenu
- 使用打字脚本为模板填充变量。这样做:
page.10 = FLUIDTEMPLATE page.10 { templateName = index.html // ... define pathes ... variables { contentMain < styles.content.get mainMenu < temp.mainMenu : } }
<div class="header"> <div class="logo">{logo->f:format.raw()}</div> <div class="main-menu"> <f:cObject typoscriptObjectPath="lib.mainMenu /> </div> </div>
在模板中,只需使用变量:page.10=FLUIDTEMPLATE 第9.10页{ templateName=index.html //…定义路径。。。 变数{ contentMain
<div class="header"> <div class="logo">{logo->f:format.raw()}</div> <div class="main-menu">{mainMenu->f:format.raw()}</div> </div>
{logo->f:format.raw()} {main menu->f:format.raw()}
- 另一种方法是使用f:cObject ViewHelper调用打字脚本的一部分。
打字稿:page.10 = FLUIDTEMPLATE page.10 { templateName = index.html // ... define pathes ... variables { contentMain < styles.content.get : } } lib.mainMenu < temp.mainMenu
流体模板如下所示:page.10=FLUIDTEMPLATE 第9.10页{ templateName=index.html //…定义路径。。。 变数{ contentMain
page.10 = FLUIDTEMPLATE page.10 { templateName = index.html // ... define pathes ... variables { contentMain < styles.content.get mainMenu < temp.mainMenu : } }
<div class="header"> <div class="logo">{logo->f:format.raw()}</div> <div class="main-menu"> <f:cObject typoscriptObjectPath="lib.mainMenu /> </div> </div>
{logo->f:format.raw()}
对于无条件呈现或严重依赖于当前页面上下文的所有元素,都应该使用模板变量 根据其他记录值呈现的元素最好通过
viewhelper使用 从技术上讲,只要结果缓存在页面缓存中,就没有多大区别。选择哪种方法只是口味和可读性的问题 这两种方法都可以使用cObject
返回可以在模板中迭代或以其他方式处理的数组或对象。特别是对于菜单生成,即将推出的dataProcessors
将有一个菜单处理器,将菜单作为数组输出。请参阅功能TYPO3 8.x LTS
(自#78672
键入3 8.5以来包括)。如果您使用类似的东西,那么我建议始终将其作为变量传递。这使它更加清晰,并且不会隐藏在模板中
我不同意pgampe的观点,因为这两种方法有很大的差异 如果您使用的是变量,那么即使前端没有使用这些内容元素,也会始终呈现这些变量。这会产生巨大的副作用,很难解决。一些例子- 你在一个栏目的页面上有一些大量的用户插件,这些插件已经不再使用了。即使它们从未显示,它们仍将被调用
- 您正在使用EXT:news和功能
。如果有一个新闻插件以某种方式通过变量呈现(但从未输出),则呈现和显示的新闻插件将丢失新闻记录excludedDisplayedNews