CObject ViewHelper <f:cObject>
This ViewHelper renders CObjects from the global TypoScript configuration.
Note
You have to ensure proper escaping (htmlspecialchars/intval/etc.) on your own!
Source code
Go to the source code of this ViewHelper: CObjectViewHelper.php (GitHub).
Table of contents
Arguments
currentValueKey
-
- Type
- string
currentValueKey
data
-
- Type
- mixed
the data to be used for rendering the cObject. Can be an object, array or string. If this argument is not set, child nodes will be used
table
-
- Type
- string
- Default
- ''
the table name associated with "data" argument. Typically tt_content or one of your custom tables. This argument should be set if rendering a FILES cObject where file references are used, or if the data argument is a database record.
typoscriptObjectPath
-
- Type
- string
- Required
- 1
the TypoScript setup path of the TypoScript object to render
Examples for the CObject ViewHelper <f:cObject>
The cObject ViewHelper can be used to render any TypoScript content object, for example on stored in the lib top-level object:
<f:cObject typoscriptObjectPath="lib.someLibObject" />
The TypoScript could look like this:
lib.someLibObject = TEXT
lib.someLibObject.value = Hello World!
Displaying content elements provided by the page-content data processor
When using the page-content data processor to display the content elements of a PAGEVIEW, the CObject ViewHelper can be used to display the actual content elements:
<f:for each="{myContent.left.records}" as="contentElement">
<f:cObject
typoscriptObjectPath="{contentElement.mainType}"
table="{contentElement.mainType}"
data="{contentElement}"
/>
</f:for>
Variable {content
already contains the correct TypoScript path
to the TypoScript top-level object tt_content.
The table storing the content elements is also called tt_
so we can use
the same variable here. Variable content
already contains the
Record object
containing the data needed to render the content element with the
CObject ViewHelper.
Use data from a plugin in TypoScript
By using the data
property you can forward data provided by the controller
to the TypoScript object doing the actual rendering:
<f:cObject
typoscriptObjectPath="lib.customHeader"
data="{myplugin.article}"
currentValueKey="title"
/>
The same can also be done in the inline notation.
{article -> f:cObject(typoscriptObjectPath: 'lib.customHeader', currentValueKey: 'title')}
The TypoScript could for example look like this:
lib.customHeader = COA
lib.customHeader {
10 = TEXT
10.field = author
20 = TEXT
20.current = 1
}
When passing an object with {data}
, the properties of the object are
accessible with
.field
in TypoScript. If only a single value is
passed or the current
is specified,
.current = 1
can be used in the TypoScript.