If I want to use typoscript like menu generation in a fluid template I have two possible ways:
use the typoscript to fill a variable for the template. doing it like this:
page.10 = FLUIDTEMPLATE
page.10 {
templateName = index.html
// ... define pathes ...
variables {
contentMain < styles.content.get
mainMenu < temp.mainMenu
:
}
}
and in the template just use the variable:
<div class="header">
<div class="logo">{logo->f:format.raw()}</div>
<div class="main-menu">{mainMenu->f:format.raw()}</div>
</div>
the other way is the usage of the f:cObject viewhelper to call a part of typoscript.
the typoscript:
page.10 = FLUIDTEMPLATE
page.10 {
templateName = index.html
// ... define pathes ...
variables {
contentMain < styles.content.get
:
}
}
lib.mainMenu < temp.mainMenu
while the fluid template looks like this:
<div class="header">
<div class="logo">{logo->f:format.raw()}</div>
<div class="main-menu">
<f:cObject typoscriptObjectPath="lib.mainMenu />
</div>
</div>
so. My question: what are the pros and cons of each way?
Are there differences for the different versions of TYPO3?
I disagree on the opinion of pgampe as there are big differences regarding those 2 approaches!
If you are using variables, those are always rendered, even though those content elements are not used in the frontend. This can have huge side effects which are really hard to tackle. Some examples
- You have some heavy USER_INT plugins on a page in a column which is not in use (anymore). those will be still called even though they are never shown
- You are using EXT:news and the feature
ExcludeDisplayedNews
. If there is a news plugin rendered somehow via variables (but never outputted), a news plugin which is rendered and shown will miss news records
You should use template variables for all elements that are rendered unconditionally or heavily depend on the current page context.
Elements that are rendered depending on other records values are better used via the cObject
viewhelper.
Technically there is not much difference as long as the result is cached in the page cache. It is only a matter of taste and readability which method to prefer.
The both method can use dataProcessors
to return arrays or objects that can be iterated or otherwise processed in the template. Especially for menu generation, the upcoming TYPO3 8.x LTS
will have a menu processor that spits out the menu as array. See feature #78672
(included since TYPO3 8.5
). If you use something like that, then I suggest to always pass it as variable. This makes it much more clear and does not hide it in the template.
https://docs.typo3.org/typo3cms/extensions/core/8-dev/Changelog/8.5/Feature-78672-IntroduceFluidDataProcessorForMenus.html