Mimis Blog

25.12.2009
13:14

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:

 

 

  1. xml = PAGE
  2. xml {
  3. typeNum = 100
  4. 10 = USER
  5. 10 {
  6. userFunc = tx_extbase_dispatcher->dispatch
  7. pluginName = Pi1
  8. extensionName = Yag
  9. controller = Album
  10. switchableControllerActions {
  11. 1 {
  12. controller = Album
  13. actions = rss
  14. }
  15. }
  16. action = rss
  17. settings =< plugin.tx_yag.settings
  18. persistence =< plugin.tx_yag.persistence
  19. view =< plugin.tx_yag.view
  20. }
  21.  
  22. config {
  23. disableAllHeaderCode = 1
  24. additionalHeaders = Content-type:application/xml
  25. xhtml_cleaning = 0
  26. admPanel = 0
  27. }
  28. }

 

 

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:

 

 

  1. plugin.tx_yag {
  2. settings {
  3.  
  4. }
  5. view {
  6. templateRootPath = EXT:yag/Resources/Private/Templates/
  7. partialRootPath = EXT:yag/Resources/Private/Partials/
  8. layoutRootPath = EXT:yag/Resources/Private/Layouts/
  9. }
  10. persistence {
  11. storagePid = 6
  12. }
  13. }

 

 

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':

 

 

  1. Tx_Extbase_Utility_Extension::configurePlugin(
  2. $_EXTKEY,
  3. 'Pi1',
  4. #...
  5. 'Album' => 'rss',
  6. #...
  7. ),
  8. 'Album' => 'rss'
  9. )
  10. );

 

 

Let's know create an action method inside the Album controller:

 

 

  1. /**
  2.  * Rss Feed Action rendering a RSS Feed of media
  3.  *
  4.  * @param Tx_Yag_Domain_Model_Album $album Album to generate rss feed for
  5.  * @return string The rendered RSS Feed
  6.  */
  7. public function rssAction(Tx_Yag_Domain_Model_Album $album = null) {
  8. if ($album != null) {
  9. $this->view->assign('album', $album);
  10. return $this->view->render();
  11. } else {
  12. return "Kein Album --> kein RSS!";
  13. }
  14. }

 

 

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

 

 

  1. <?xml version="1.0" encoding="utf-8" standalone="yes"?>
  2. <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
  3. xmlns:atom="http://www.w3.org/2005/Atom">
  4. <channel>
  5. <f:for each="{album.images}" as="image"><item>
  6. <title>{image.title}</title>
  7. <media:description>{image.description}</media:description>
  8. <link>{image.single.filePath}</link>
  9. <media:thumbnail url="{image.thumb.filePath}"/>
  10. <media:content url="{image.single.filePath}"/>
  11. </item>
  12. </f:for></channel>
  13. </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
  •  
Gravatar: Sebastian KurfürstSebastian Kurfürst
31.12.2009
11:48
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

Gravatar: MimiMimi
01.01.2010
04:15
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

Gravatar: KimPixelKimPixel
12.07.2010
13:52
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}]]>"

Gravatar: GrandFelixGrandFelix
26.08.2010
11:27
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

Gravatar: MimiMimi
26.08.2010
22:02
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 =

}

Mein Kommentar

Ich möchte über jeden weiteren Kommentar in diesem Post benachrichtigt werden.

Zurück

< < Juli 2010 > >
S M T W T F S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Kategorien

  • [-](J)DAV(28)
  • [-]Bergsteigen(30)
  • [-]Computer & Informatik(63)
    • PHP(2)
    • [-]Typo3(54)
  • [-]Fotografie(47)
  • Kaktusteam(3)
  • [-]Laufen(4)
  • Musik & Filme(3)
  • [-]Radfahren(0)
  • [-]Reisen(11)
  • Sonstiges...(4)
  • Studium...(6)

Letzte Kommentare

Using Extbase Controller and Action in TemplaVoila TS Lib
26.08.2010 22:02
insert in TS
26.08.2010 11:27
Gut geschildert
23.08.2010 22:05
Good Timing
21.08.2010 01:59

Archiv

Kopieren Sie diesen Link in Ihren RSS Reader

RSS 0.91Posts
RSS 2.0Posts

Social Bookmarking

Bookmark bei: Mr. Wong Bookmark bei: Webnews Bookmark bei: Icio Bookmark bei: Oneview Bookmark bei: Linkarena Bookmark bei: Favoriten Bookmark bei: Seekxl Bookmark bei: Favit Bookmark bei: Social Bookmarking Tool Bookmark bei: Power Oldie Bookmark bei: Bookmarks.cc Bookmark bei: Newskick Bookmark bei: Newsider Bookmark bei: Linksilo Bookmark bei: Readster Bookmark bei: Folkd Bookmark bei: Yigg Bookmark bei: Digg Bookmark bei: Del.icio.us Bookmark bei: Reddit Bookmark bei: Simpy Bookmark bei: StumbleUpon Bookmark bei: Slashdot Bookmark bei: Netscape Bookmark bei: Furl Bookmark bei: Yahoo Bookmark bei: Spurl Bookmark bei: Google Bookmark bei: Blinklist Bookmark bei: Blogmarks Bookmark bei: Diigo Bookmark bei: Technorati Bookmark bei: Newsvine Bookmark bei: Blinkbits Bookmark bei: Ma.Gnolia Bookmark bei: Smarking Bookmark bei: Netvouz Information