CObject ViewHelper <f:cObject>

This ViewHelper renders CObjects from the global TypoScript configuration.

Source code

Go to the source code of this ViewHelper: CObjectViewHelper.php (GitHub).

Arguments

currentValueKey

currentValueKey
Type
string
currentValueKey

data

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

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

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:

packages/my_sitepackage/Resources/Private/Templates/Pages/Default.html
<f:cObject typoscriptObjectPath="lib.someLibObject" />
Copied!

The TypoScript could look like this:

packages/my_sitepackage/Configuration/Sets/MySet/setup.typoscript
lib.someLibObject = TEXT
lib.someLibObject.value = Hello World!
Copied!

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:

packages/my_sitepackage/Resources/Private/Templates/Pages/Default.html
<f:for each="{myContent.left.records}" as="contentElement">
    <f:cObject
        typoscriptObjectPath="{contentElement.mainType}"
        table="{contentElement.mainType}"
        data="{contentElement}"
    />
</f:for>
Copied!

Variable {contentElement.mainType} already contains the correct TypoScript path to the TypoScript top-level object tt_content.

The table storing the content elements is also called tt_content so we can use the same variable here. Variable contentElement 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:

packages/my_extension/Resources/Private/Templates/Plugin/Default.html
<f:cObject
    typoscriptObjectPath="lib.customHeader"
    data="{myplugin.article}"
    currentValueKey="title"
/>
Copied!

The same can also be done in the inline notation.

packages/my_extension/Resources/Private/Templates/Plugin/Default.html
{article -> f:cObject(typoscriptObjectPath: 'lib.customHeader', currentValueKey: 'title')}
Copied!

The TypoScript could for example look like this:

packages/my_sitepackage/Configuration/Sets/MySet/setup.typoscript
lib.customHeader = COA
lib.customHeader {
   10 = TEXT
   10.field = author
   20 = TEXT
   20.current = 1
}
Copied!

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 currentValueKey is specified, .current = 1 can be used in the TypoScript.