So, jetzt wird es mal langsam Zeit auch die anderen Kategorien zu füllen. Dieses mal ist es nur ein kurzer Snippet um über das cObj Elemente aus der tt_content zu ziehen.
<?php $cConf = array( 'tables' => 'tt_content', 'source' => '234', //single uid or komma separated uids 'wrap' => '<div class="mydiv">|</div>', 'dontCheckPid' => 1, ); $content .= $GLOBALS['TSFE']->cObj->RECORDS($cConf); >?
In Extbase kann das natürlich auch sehr schön über einen Viewhelper realisiert werden ;-) Als kleine Fleißaufgabe könnte man diesen erweitern um auch die wrap Funktion des RECORDS Objektes zu unterstützen.
<?php
//http://www.in2code.de/community/snippet-datenbank/snippets/detail/content-element-viewhelper-um-seiteninhalte-in-fluid-zu-rendern/?tx_in2snippets_pi1%5Bcontroller%5D=Snippet&cHash=d2f09c6efd1f4f244f295418f241a25d
/**
* Shows Content Element
*
* @package TYPO3
* @subpackage Fluid
*/
class Tx_Powermail_ViewHelpers_ContentElementViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* @var Tx_Extbase_Configuration_ConfigurationManagerInterface
*/
protected $configurationManager;
/**
* @var Content Object
*/
protected $cObj;
/**
* Parse a content element
*
* @param int UID of any content element
* @return string Parsed Content Element
*/
public function render($uid) {
$conf = array( // config
'tables' => 'tt_content',
'source' => $uid,
'dontCheckPid' => 1
);
return $this->cObj->RECORDS($conf);
}
/**
* Injects the Configuration Manager
*
* @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
* @return void
*/
public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
$this->configurationManager = $configurationManager;
$this->cObj = $this->configurationManager->getContentObject();
}
}
/*aufruf in fluid template mit
<!-- FLUID: Render Content Element with uid 123 -->
<vh:ContentElement uid="123" />
*/
?>
Ein Gedanke zu „TYPO3: tt_content über cObj holen, auch als Viewhelper“
Kommentare sind geschlossen.