[TYPO3-english] TYPO3 6.2.x: adding extra fields to tx_news not showing up in front-end
Bert Hiddink [BENDOO e-work solutions]
hiddink at bendoo.nl
Thu Feb 9 17:03:19 CET 2017
Hello,
I followed this example
<https://t3brightside.com/blog/article/extending-extnews-with-a-fal-compilant-audio-and-customized-youtube-video/>
...to add some extra fields to tx_news, it even includes a sample extension.
In the backend, the added fields show up and I can add/edit values.
However, when trying to show the values in Fluid with:
{newsItem.txNewscustomYoutube}
...no output is shown.
Is this an outdated approach? Any help?
Thanks in advance!
Bert
ext_tables.php:
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
$tempColumns = array(
'tx_newscustom_youtube' => array(
'exclude' => 0,
'label' =>
'LLL:EXT:newscustom/locallang_db.xml:tx_news_domain_model_news.tx_newscustom_youtube',
'config' => array(
'type' => 'input',
'size' => '30',
)
),
);
t3lib_div::loadTCA('tx_news_domain_model_news');
t3lib_extMgm::addTCAcolumns('tx_news_domain_model_news',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('tx_news_domain_model_news','tx_newscustom_youtube;;;;1-1-1,
tx_newscustom_soundcloud, tx_newscustom_audiofile');
?>
Classes/Domain/Model/News.php:
<?php
class Tx_Newscustom_Domain_Model_News extends Tx_News_Domain_Model_News {
/**
* @var string
*/
protected $txNewscustomSoundcloud;
/**
* @var string
*/
protected $txNewscustomYoutube;
/**
* @var string
*/
protected $txNewscustomAudiofile;
/**
* @var string
*/
public function getTxNewscustomSoundcloud() {
return $this->txNewscustomSoundcloud;
}
/**
* @var string
*/
public function getTxNewscustomYoutube() {
return $this->txNewscustomYoutube;
}
/**
* @var string
*/
public function getTxNewscustomAudiofile() {
$fileRepository =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
$fileObjects =
$fileRepository->findByRelation('tx_news_domain_model_news', 'file',
$this->getUid());
$fileObject = (is_array($fileObjects)) ?
array_shift($fileObjects) : $fileObjects;
return (is_object($fileObject) && method_exists($fileObject,
'getPublicUrl') && $fileObject->getPublicUrl()) ?
$fileObject->getPublicUrl() : '';
}
}
?>
Resources/Private/extend-news.txt:
Domain/Model/News
FLUID:
<!-- In news/Resources/Private/Partials/List/Item.html or
news/Resources/Private/Templates/News/Detail.html -->
<f:if condition="{newsItem.txNewscustomAudiofile}">
<audio controls>
<source src="{newsItem.txNewscustomAudiofile}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</f:if>
<!-- Or for a customized Youtube video -->
<f:if condition="{newsItem.txNewscustomYoutube}">
<div class="videoCont">
<iframe
src="http://www.youtube.com/embed/{newsItem.txNewscustomYoutube}?HD=1&theme=light&color=white&autohide=1&showinfo=0&rel=0"
width="922" height="524"></iframe>
</div>
</f:if>
More information about the TYPO3-english
mailing list