How I can render Content Object from tt_content i my extension with php in Typo3 6.1.5

别等时光非礼了梦想. 提交于 2019-12-22 09:57:56

问题


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

How can I do this?

\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer ?


回答1:


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);



回答2:


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');



回答3:


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/




回答4:


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 vie helper, see here



来源:https://stackoverflow.com/questions/20283998/how-i-can-render-content-object-from-tt-content-i-my-extension-with-php-in-typo3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!