[TYPO3-ttnews] tx_news Meta to page Meta "injection"
Thomas Skierlo
pubtsk1 at pix-pro.eu
Wed Feb 20 13:58:57 CET 2013
Hi,
I'm currently working on a ViewHelper for news detail pages, which
injects news Meta properties into page Meta properties. The process is
similar to the current manipulation of tx_news for the page title, via
something like $GLOBALS['TSFE']->page['title'] = $titleText;
The reason to use a helper for more than just the page title is to allow
generation of meta tags (Open graph, Dublin Core, ...you name it) by
pure TS -- without the need to distinguish between regular pages and
news detail pages by a condition (we already have that hidden in the
news detail view). The helper allows arguments like "prepend, append, or
replace" for page title, description, keywords, author and so on. This
part works like charme. My problems start with timestamp based dates,
like crdate, tstamp, startime, endtime. All news fields have matching
page properties, but I did not find a way to handle them by TS without
getting an "object of datatime can't be converted to string" error. This
questions translates to something like "how can I output page:crdate
date by TS?" Any ideas? (I'll probably will have a full understanding of
Typoscript once it's obsolete :-)
My second question. Currently I'm using arguments in the helper, like:
/**
* Inject News Meta properties into current page (use helper on news detail page only!!!)
* @param string $titleText The news title
* @param string $titleAction May be 'prepend', 'append', 'replace'
* @param string $descriptionText May be 'prepend', 'append' or 'replace'
* @param string $descriptionAction May be 'prepend', 'append' or 'replace'
* @param string $keywords The string of news keywords
* @param string $keywordsAction May be 'prepend', 'append' or 'replace'
* @param string $author Author of news article
* @param string $authorAction May be 'prepend', 'append' or 'replace'
* @param integer $dateCreated If set, Page creation date will be set to news creation date
* @return void
*/
public function render(
$titleText = '', $titleAction = 'replace',
$descriptionText = '', $descriptionAction = 'replace',
$keywords = '', $keywordsAction ='append',
$author = '', $authorAction = 'replace',
$dateCreated = ''
) {....}
The helper call in detail view would look like:
<nittygritty:news.injectNewsMeta
titleText="{newsItem.title}"
descriptionText="{newsItem.teaser}"
descriptionAction="prepend" keywords="{newsItem.keywords}"
keywordsAction="prepend" author="{newsItem.author}"
authorAction="prepend"
dateCreated="{newsItem.crdate}"
/>
This works, but it might be even nicer to push the whole $newsItem into
the helper instead of resolved strings. I was able to "pull" the whole
object into my helper as "Tx_News_Domain_Model_News $news" without an
error, but inside my helper I couldn't access it's properties. Any ideas
about best way to solve this?
I'm still new to this extbase thing. Sorry for asking (possibly) stupid
questions.
Regards,
Thomas
More information about the TYPO3-project-tt-news
mailing list