How to render a Content Object from tt_content in my extension with PHP in Typo3 6.1.5

13.8k views Asked by At

I need to render with my extension a specific content from tt_content.

How can I do this?

\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer ?

4

There are 4 answers

8
nbar On BEST ANSWER

In Extbase extensions $this->cObj is no more available in the current scope, so you need to get it first before you can use:

$cObj = $this->configurationManager->getContentObject();

$ttContentConfig = array(
    'tables'       => 'tt_content',
    'source'       => 123,
    'dontCheckPid' => 1
);

$content .= $cObj->RECORDS($ttContentConfig);
1
Daniel On

You can use the Typoscript CONTENT object and pass it to a fluid ViewHelper:

lib.myContent = CONTENT
lib.myContent {
  table = tt_content
  select {
    pidInList = yourPid
    where = uid=yourContentElementID
  }
}

In your extension using Fluid:

<f:cObject typoscriptObjectPath="lib.myContent" />

You can also pass values through the viewHelper, see here

0
barcasal On

You can do it from the controller too. If I understood your question, you may want to try this

$cObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
0
Jainish On

Following script will be use PI base extension.

$uid = $this->cObj->data['uid'];

if ($this->cObj->data['_LOCALIZED_UID']) {
    $uid = $this->cObj->data['_LOCALIZED_UID'];
}

Following script will be use in EXT BASE extension.

$this->contentObj = $this->configurationManager->getContentObject();
$uid = $this->contentObj->data['uid'];

For more information about TYPO3 stuff you may visit my blog

https://jainishsenjaliya.wordpress.com/2014/08/21/how-to-get-current-tt_content-uid-in-pi-base-and-extbase-extension/