Skip to Main Content

RSS Feed in TYPO3 Part 2 - A Middleware Approach

In the first part, you learnt how I designed the RSS feed and what data I need.
When I asked Marc about this, he quickly realised: ‘You're too late.’ But what did he mean by that? Late for work? That couldn't be, since I was on time.

But then I realised what he was getting at: first querying the pagetype via TypoScript, then executing the database queries and then, after TYPO3 is fully loaded, outputting the XML file would be unnecessarily late. This slows down the loading time.

So I had to ask myself: when is the right time to intervene? Early enough to run my database queries and process the request, but still before a frontend output has occurred and TYPO3 is fully awake. The solution? A middleware.

You can find out how to create middleware and more in the official TYPO3 documentation.

The Middleware Approach

My RssPageMiddleware is called in the middleware stack.
Based on the page type, which is determined from the request, I check whether the RSS feed is be called. If so, the feed is created, but only if it has not already been generated and cached within the last 30 minutes. Otherwise the cache answers the call.

But how exactly do I create my RSS feed?

The Database Query

First I determine the site language and the corresponding language ID from the request so that the RSS feed displays the blog posts in the selected language.

This is followed by the database query: all blog posts that are neither hidden nor deleted are loaded. Fortunately, the TYPO3 QueryBuilder takes this into account by default.

With F7, we have also decided to display teaser images in the RSS feed, which must also be retrieved from the database.

Please ensure that this is the case: If an image is available, only the path of the RSS feed is output, not the image object itself. If neither an image nor a fallback image exists, no image is output instead.


The information is saved as an array and then rendered as RSS items.

The output of the RSS feed

There are various ways to create the view for the RSS feed.

As my feed is based on a XML file, I decided to generate it directly in the middleware.
To do this, I create a DOM object with PHP and add the individual items of the feed to it. The database query first returns a structured array, which is run through in a loop and converted into XML format.

Our RSS feed is live!

And now I am pleased to announce: Our RSS feed is live!
You can access it in the footer or directly here:

f7.de/en/rss.xml