---
title: "CObject ViewHelper <f:cObject>"
manual: "Fluid ViewHelper Reference"
version: "13.4"
permalink: "https://docs.typo3.org/permalink/t3viewhelper:typo3-fluid-cobject@13.4"
source: "Global/CObject.rst"
modified: "2026-09-16T11:38:27+00:00"
---

# CObject ViewHelper `<f:cObject>`

ViewHelper to render CObjects (objects containing rendering definitions for records/elements), using the global TypoScript configuration.

**Note:** You have to ensure proper escaping (`htmlspecialchars`/`intval`/etc.) on your own!

Go to the source code of this ViewHelper: [CObjectViewHelper.php (GitHub)](https://github.com/TYPO3/typo3/blob/main/typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php).

**Table of contents**

-   [Arguments](https://docs.typo3.org/permalink/t3viewhelper:arguments@13.4)
-   [Examples for the CObject ViewHelper <f:cObject>](https://docs.typo3.org/permalink/t3viewhelper:examples-for-the-cobject-viewhelper-f-cobject@13.4)

## 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:* true

    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](https://docs.typo3.org/m/typo3/reference-typoscript/13.4/en-us/TopLevelObjects/Other.html#tlo-lib)
top-level object:

**packages/my_sitepackage/Resources/Private/Templates/Pages/Default.html**

```html
<f:cObject typoscriptObjectPath="lib.someLibObject" />
```

The TypoScript could look like this:

**packages/my_sitepackage/Configuration/Sets/MySet/setup.typoscript**

```html
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](https://docs.typo3.org/m/typo3/reference-typoscript/13.4/en-us/DataProcessing/PageContentFetchingProcessor.html#PageContentFetchingProcessor)
to display the content elements of a
[PAGEVIEW](https://docs.typo3.org/m/typo3/reference-typoscript/13.4/en-us/ContentObjects/Pageview/Index.html#cobj-pageview),
the CObject ViewHelper can be used to display the actual content elements:

**packages/my_sitepackage/Resources/Private/Templates/Pages/Default.html**

```html
<f:for each="{myContent.left.records}" as="contentElement">
    <f:cObject
        typoscriptObjectPath="{contentElement.mainType}"
        table="{contentElement.mainType}"
        data="{contentElement}"
    />
</f:for>
```

Variable `{contentElement.mainType}` already contains the correct TypoScript path
to the TypoScript top-level object [tt_content](https://docs.typo3.org/m/typo3/reference-typoscript/13.4/en-us/TopLevelObjects/Other.html#tlo-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](https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/ApiOverview/Database/DatabaseRecords/RecordObjects.html#record_objects)
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**

```html
<f:cObject
    typoscriptObjectPath="lib.customHeader"
    data="{myplugin.article}"
    currentValueKey="title"
/>
```

The same can also be done in the inline notation.

**packages/my_extension/Resources/Private/Templates/Plugin/Default.html**

```html
{article -> f:cObject(typoscriptObjectPath: 'lib.customHeader', currentValueKey: 'title')}
```

The TypoScript could for example look like this:

**packages/my_sitepackage/Configuration/Sets/MySet/setup.typoscript**

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

### Use data from a TypoScript ContentObject

As an example of a more advanced use case, the cObject viewhelper can pass
content data from a Fluid template to a content object defined in TypoScript. The
following example demonstrates this with a user counter. The user counter is in
a blog post (the blog post has a count of how many times it has been viewed.)

Add the viewhelper to your Fluid template. This can be done in 3 different
ways. The basic tag syntax:

**EXT:my_extension/Resources/Private/Templates/SomeTemplate.html**

```html
<f:cObject typoscriptObjectPath="lib.myCounter">{post.viewCount}</f:cObject>
```

Or a self-closing tag. Data is passed in the `data` attribute.

**EXT:my_extension/Resources/Private/Templates/SomeTemplate.html**

```html
<f:cObject typoscriptObjectPath="lib.myCounter" data="{post.viewCount}" />
```

Or inline notation, which is easy to read and understand (from left to right):

**EXT:my_extension/Resources/Private/Templates/SomeTemplate.html**

```html
{post.viewCount -> f:cObject(typoscriptObjectPath: 'lib.myCounter')}
```

Then, add TypoScript (to your TypoScript template) to process this data. In our
example below, the `stdWrap` attribute `current`
works like a switch: if set to 1, it contains the value that was passed to the
TypoScript object from the Fluid template:

**EXT:my_extension/Configuration/Sets/MyExtension/setup.typoscript**

```typoscript
lib.myCounter = TEXT
lib.myCounter {
  current = 1
  wrap = <strong>|</strong>
}
```

This TypoScript snippet outputs the current number of visits in bold.

We can easily modify this TypoScript to output the user counter as an image instead
of text:

**EXT:my_extension/Configuration/Sets/MyExtension/setup.typoscript**

```typoscript
lib.myCounter = IMAGE
lib.myCounter {
  file = GIFBUILDER
  file {
     10 = TEXT
     10.text.current = 1
  }
}
```

#### Passing objects to TypoScript

Up till now, we have only been passing a single value to the TypoScript object.
However, it is also possible to pass multiple values, useful for selecting  which value to
use or concatenating values, or you can pass objects (here the `post` object):

**EXT:my_extension/Resources/Private/Templates/SomeTemplate.html**

```html
{post -> f:cObject(typoscriptObjectPath: 'lib.myCounter')}
```

But how do we access the object's properties in our TypoScript? By setting the
`field` property of `stdWrap` (in a `COA`):

**EXT:my_extension/Configuration/Sets/MyExtension/setup.typoscript**

```typoscript
lib.myCounter = COA
lib.myCounter {
  10 = TEXT
  10.field = title
  20 = TEXT
  20.field = viewCount
  wrap = (<strong>|</strong>)
}
```

This TypoScript snippet outputs the title of the blog and the number of page visits in parentheses.

#### Using `current` to pass values

It is also possible to use the `current` switch here.
If you set the property `currentValueKey`
in the cObject ViewHelper, the value will be available in
the TypoScript template as `current`. That is especially useful
when you want to emphasize that the value is very
*important* for the TypoScript template. For example, the
*number of visits* is significant in our view
counter:

**EXT:my_extension/Resources/Private/Templates/SomeTemplate.html**

```html
{post -> f:cObject(typoscriptObjectPath: 'lib.myCounter', currentValueKey: 'viewCount')}
```

Then, in the TypoScript template, use `field` aswell as
`current` to output the value of the view count. The following
TypoScript snippet outputs the same information as above:

**EXT:my_extension/Configuration/Sets/MyExtension/setup.typoscript**

```typoscript
lib.myCounter = COA
lib.myCounter {
  10 = TEXT
  10.field = title
  20 = TEXT
  20.current = 1
  wrap = (<strong>|</strong>)
}
```

Using `current` makes the TypoScript easier to read and the logic
easier to understand.

In summary, the cObject ViewHelper is a powerful option to embed TypoScript
expressions in Fluid templates.
