ExtBase Cookbook 6 - How to generate RSS Feeds with ExtBase
As I wanted to add Cooliris functionality to my gallery extension, I had to create a RSS-Feed. As this has not yet been done within the Blog-Extension, I wanted to show how I implemented this.
First of all, we create a new page type inside the 'Configuration/TypoScript/setup.txt' file:
xml = PAGE xml { typeNum = 100 10 = USER 10 { userFunc = tx_extbase_dispatcher->dispatch pluginName = Pi1 extensionName = Yag controller = Album switchableControllerActions { 1 { controller = Album actions = rss } } action = rss settings =< plugin.tx_yag.settings persistence =< plugin.tx_yag.persistence view =< plugin.tx_yag.view } config { disableAllHeaderCode = 1 additionalHeaders = Content-type:application/xml xhtml_cleaning = 0 admPanel = 0 } }
There is one other important line to add to your setup.txt in order to make persistence work. Without this line, I got an "Expected parameter 1 to be object, NULL given" exception:
plugin.tx_yag { settings { } view { templateRootPath = EXT:yag/Resources/Private/Templates/ partialRootPath = EXT:yag/Resources/Private/Partials/ layoutRootPath = EXT:yag/Resources/Private/Layouts/ } persistence { storagePid = 6 } }
We generate a new page type 100, which is responsible for showing our RSS XML. We use a USER object to register an ExtBase dispatcher that should handle the RSS Request. The next lines are taken from the 'Tx_Extbase_Utility_Extension' class, which is normally used to register ExtBase based extions as page contents. The last lines prevents rendering of headers by typo3.
I'm not sure, whether the next step is required, but I registered the RSS action for the controller inside 'ext_localconf.php':
Let's know create an action method inside the Album controller:
/** * Rss Feed Action rendering a RSS Feed of media * * @param Tx_Yag_Domain_Model_Album $album Album to generate rss feed for * @return string The rendered RSS Feed */ public function rssAction(Tx_Yag_Domain_Model_Album $album = null) { if ($album != null) { $this->view->assign('album', $album); return $this->view->render(); } else { return "Kein Album --> kein RSS!"; } }
Last but not least, we need a template for rendering the feed. Here's what I wrote for Cooliris plugin ('Resources/Private/Templates/Album/rss.html'):
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <f:for each="{album.images}" as="image"><item> <title>{image.title}</title> <media:description>{image.description}</media:description> <link>{image.single.filePath}</link> <media:thumbnail url="{image.thumb.filePath}"/> <media:content url="{image.single.filePath}"/> </item> </f:for></channel> </rss>
Here it is very important, that you spare the newline behind the '<f:section...>' tag, otherwise, the generated XML is not parsed by the browser!
- 5 Kommentare



Layout nicht nötig
Hey,
ich würde sagen, dass Du hier keine Layouts nutzen musst :-) Es ist ja eh leer!
Viele Grüße,
Sebastian
Layout gelöscht
Danke, Sebastian! Ich hab das Layout entfernt und das Rezept entsprechend angepasst. Ich habe leider gedacht, man bräuchte immer ein Layout, darum kam's zu dem Quatsch...
Grüße
Mimi
HTMLViewHelper
super Artikel! damit habe ich jetzt in wenigen Minuten einen RSS Feed für meine "news" Extension erzeugt.
Leider ist es nicht möglich CDATA zu verwenden da dann auch keine Fluid Viewhelper und Marker mehr ersetzt werden..
z.B. "{newsItem.bodytext}]]>"
insert in TS
Hi,
I have one extension created with extbase. Now I have some element mapped in TV and I wan to fill it with one action from one controller form this extension. In extension I have two controllers. I have also defined Pi1 and Pi2.. How I can now make in TS that lib.someVar will be filled with some action from one controller? Any tip?
Thanks
Using Extbase Controller and Action in TemplaVoila TS Lib
Here's the answer to the question above:
lib.someVar = USER
lib.someVar {
userFunc = tx_extbase_dispatcher->dispatch
pluginName = Pi1
extensionName =
controller =
switchableControllerActions {
1 {
controller =
actions =
}
}
action =
}