FLUIDTEMPLATE
An object of type FLUIDTEMPLATE
combines TypoScript with the Fluid
templating engine.
A FLUIDTEMPLATE
object generates content using Fluid templates.
It can be used in content elements
or to generate content in the top-level page object
(see the example on this page).
New in version 13.1
Starting with TYPO3 v13.1 you can use the PAGEVIEW content object for templates on page-level. It reduces the amount of TypoScript needed to render a page in the TYPO3 frontend.
See section Migration from FLUIDTEMPLATE to PAGEVIEW.
Table of content
Data available in Fluid templates
New in version 13.2
The FLUIDTEMPLATE can now be used in combination with the record-transformation data processor for additional computed information. See also Example: Usage with FLUIDTEMPLATE
The following data is available in the Fluid template:
-
The content of the current
data
array.- At page level it contains the current page record.
- If the
FLUIDTEMPLATE
is used in the context of the Fluid ViewHelper CObject ViewHelper <f:cObject> it contains data in the Fluid Propertydata
. - If called in the context of Extbase it contains the data assigned to the view in the Controller.
- Use the record-transformation data processor to get additional computed
information from the
data
array.
- The
settings
array set by the parameter settings - Variables in the variables setting
- Data retrieved by data processors
You can use the debug ViewHelper
to output all available data using the magic {_
variable:
<f:debug>{_all}</f:debug>
Properties
cache
-
- Type
- cache
See cache function description for details.
dataProcessing
-
- Type
- array of class references by full namespace
Add one or more processors to manipulate the
$data
variable of the currently rendered content object, such as tt_content or page. Use the sub-propertyoptions
to pass parameters to the processor class.Note
This content was moved to the subpage Data processors.
extbase.controllerActionName
extbase.controllerExtensionName
extbase.controllerName
extbase.pluginName
file
format
-
- Type
- keyword / stdWrap
- Default
- html
format
sets the format of the current request. It can be something like "html", "xml", "png", "json" or even "rss.xml" or something similar.
layoutRootPath
-
Sets a specific layout path, usually
EXT:
or a folder below that path.my_ extension/ Resources/ Private/ Layouts/ Note
It is recommended to use Properties (note the plural "s") as it can easily be extended by custom templates in the sitepackage.
layoutRootPaths
-
Note
Note the plural -s in "layoutRootPaths"!
Note
If you want to extend layoutRootPaths conditionally, best practice is to use Conditions instead of the "if" function.
Used to define several paths for layouts, which will be tried in reversed order (the paths are searched from bottom to top). The first folder where the desired layout is found is used. If the array keys are numeric, they are first sorted and then tried in reversed order.
Examplepage = PAGE page { 10 = FLUIDTEMPLATE 10 { file = EXT:my_sitepackage/Resources/Private/Templates/Main.html layoutRootPaths { 10 = EXT:my_base_sitepackage/Resources/Private/Layouts 20 = EXT:my_sitepackage/Resources/Private/Layouts } } }
If property layoutRootPath (singular) is also used, it will be placed as the first option in the list of fall back paths.
partialRootPath
-
Sets a specific partial path, usually
EXT:
or a folder below that path.my_ extension/ Resources/ Private/ Partials/ Note
It is recommended to use Properties (note the plural "s") as it can be easily extended by custom templates provided by the sitepackage.
partialRootPaths
-
Note
Note the plural -s in "partialRootPaths"!
Note
If you want to extend partialRootPaths conditionally, best practice is to use Conditions instead of the "if" function.
Used to define several paths for partials, which will be tried in reverse order. The first folder where the desired partial is found is used. The keys of the array define the order.
See layoutRootPaths for more details.
settings
-
- Type
- array of keys
Sets the settings array in the fluid template. The value can then be used in the view.
Examplepage = PAGE page { 10 = FLUIDTEMPLATE 10 { file = EXT:site_default/Resources/Private/Templates/MyTemplate.html settings { copyrightYear = 2013 } } }
To access copyrightYear in the template file use:
{settings.copyrightYear}
Copied!Apart from setting a key-value pair as in the example, you can also reference objects or access constants.
stdWrap
-
- Type
- ->stdWrap
Provides the usual stdWrap functionality.
template
-
- Type
- cObject
Use this property to define the content object which should be used as a template file. It is an alternative to ".file"; if ".template" is set, it takes precedence.
templateName
-
This name is used together with the set format to find the template in the templateRootPaths. Use this property to define a content object to use as a template file. It is an alternative to
.file
. If.template
is set, it takes precedence.Name Example 1lib.stdContent = FLUIDTEMPLATE lib.stdContent { templateName = Default layoutRootPaths { 10 = EXT:frontend/Resources/Private/Layouts 20 = EXT:sitemodification/Resources/Private/Layouts } partialRootPaths { 10 = EXT:frontend/Resources/Private/Partials 20 = EXT:sitemodification/Resources/Private/Partials } templateRootPaths { 10 = EXT:frontend/Resources/Private/Templates 20 = EXT:sitemodification/Resources/Private/Templates } variables { foo = TEXT foo.value = bar } }
Example 2lib.stdContent = FLUIDTEMPLATE lib.stdContent { templateName = TEXT templateName.stdWrap { cObject = TEXT cObject { data = levelfield:-2,backend_layout_next_level,slide override.field = backend_layout split { token = frontend__ 1.current = 1 1.wrap = | } } ifEmpty = Default } layoutRootPaths { 10 = EXT:frontend/Resources/Private/Layouts 20 = EXT:sitemodification/Resources/Private/Layouts } partialRootPaths { 10 = EXT:frontend/Resources/Private/Partials 20 = EXT:sitemodification/Resources/Private/Partials } templateRootPaths { 10 = EXT:frontend/Resources/Private/Templates 20 = EXT:sitemodification/Resources/Private/Templates } variables { foo = bar } }
templateRootPath
-
- Type
- file path /stdWrap
Sets a specific template path, usually
EXT:
or a folder below that path.my_ extension/ Resources/ Private/ Templates/ Note
It is recommended to use Properties (note the plural "s") as it can be easily extended by custom templates provided by the sitepackage.
templateRootPaths
-
- Type
- array of file paths with stdWrap
Note
Note the plural -s in "templateRootPaths"!
Note
If you want to extend templateRootPaths conditionally, best practice is to use Conditions instead of the "if" function.
Used to define several paths for templates, which will be tried in reverse order (the paths are searched from bottom to top). The first folder where the desired layout is found is used. If the array keys are numeric, they are first sorted and then tried in reverse order.
Useful in combination with the templateName property.
Example
variables
-
- Type
- (array of cObjects)
Sets the variables that will be available in the fluid template. The keys are the variable names in Fluid.
Reserved variables are "data" and "current", which are set automatically to the current data set.
Example: Usage with RecordTransformationProcessor
New in version 13.2
The FLUIDTEMPLATE can now be used in combination with the record-transformation data processor for additional computed information.
The record-transformation data processor transforms the current data array of
the FLUIDTEMPLATE
to a record object.
This can be used for content elements of Fluid Styled Content or custom ones. In this example the Fluid Styled Content element "Text" has its data transformed for easier and enhanced usage.
# tt_content.text = FLUIDTEMPLATE
tt_content.text {
templateName = Text
dataProcessing {
10 = record-transformation
10 {
as = data
}
}
}
For usage of the variables within Fluid see Example: Usage with FLUIDTEMPLATE.
Example
New in version 13.1
It is recommended to use PAGEVIEW for page templates starting with TYPO3 v13.1. See How to migrate to PAGEVIEW
The Fluid template in
EXT:
could look
like this:
<h1>{data.title}<f:if condition="{data.subtitle}">, {data.subtitle}</f:if></h1>
<h3>{mylabel}</h3>
<f:format.html>{data.bodytext}</f:format.html>
<p>© {settings.copyrightYear}</p>
You could use it with TypoScript code like this:
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = MyTemplate
templateRootPaths {
10 = EXT:my_sitepackage/Resources/Private/Templates
}
partialRootPaths {
10 = EXT:my_sitepackage/Resources/Private/Partials
}
variables {
mylabel = TEXT
mylabel.value = Label coming from TypoScript!
}
settings {
# Get the copyright year from a TypoScript constant.
copyrightYear = {$year}
}
}
As a result, the page title and the label from TypoScript will be inserted as titles. The copyright year will be taken from the TypoScript constant "year".
See also
Migration from FLUIDTEMPLATE
to PAGEVIEW
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName {
stdWrap {
cObject = TEXT
cObject {
data = levelfield:-2, backend_layout_next_level, slide
override {
field = backend_layout
}
split {
token = pagets__
1 {
current = 1
wrap = |
}
}
}
ifEmpty = Standard
}
}
templateRootPaths {
100 = EXT:my_sitepackage/Resources/Private/Templates/Pages/
}
partialRootPaths {
100 = EXT:my_sitepackage/Resources/Private/Partials/Pages/
}
layoutRootPaths {
100 = EXT:my_sitepackage/Resources/Private/Layouts/Pages/
}
variables {
pageUid = TEXT
pageUid.data = page:uid
pageTitle = TEXT
pageTitle.data = page:title
pageSubtitle = TEXT
pageSubtitle.data = page:subtitle
parentPageTitle = TEXT
parentPageTitle.data = levelfield:-1:title
}
dataProcessing {
10 = menu
10.as = mainMenu
}
}
}
page = PAGE
page {
10 = PAGEVIEW
10 {
paths {
100 = EXT:my_sitepackage/Resources/Private/PageView/
}
variables {
parentPageTitle = TEXT
parentPageTitle.data = levelfield:-1:title
}
dataProcessing {
10 = menu
10.as = mainMenu
}
}
}
In Fluid, the pageUid is available as {page.
and pageTitle
as {page.
, the subtitle with {page.
.
In this example some Fluid templates have to be moved:
EXT:
my_ sitepackage/ Resources/ Private/ Templates/ Pages/ - Move files to
EXT:
my_ sitepackage/ Resources/ Private/ Page View/ Pages/ EXT:
my_ sitepackage/ Resources/ Private/ Partials/ Pages/ - Move files to
EXT:
my_ sitepackage/ Resources/ Private/ Page View/ Partials/ EXT:
my_ sitepackage/ Resources/ Private/ Layouts/ Pages/ - Move files to
EXT:
my_ sitepackage/ Resources/ Private/ Page View/ Layouts/
If the Private
folder previously looked like this:
It should look like this afterwards: