Search code examples
typo3typo3-extensions

Generate json feed from ext:news


TYPO3 7.6.16 ext:news 5.3.2

We're looking to create a json stream of news stories that have been created in the CMS so that we can consume the feed in other applications.  For each element in the feed we're looking include some simple properties such as the news story name, when it was published and a link to the news story, so that we can direct someone back to the relevant page on the Website.  

We've been able to return a list of news stories by querying the tx_news_domain_model_news table.  From this table we've been able to query all the information that we need from the story, but we're having trouble building a link to the story.

The links that the news plugin is building for each story at the moment takes the form:

/story/tx_news_pi1%5Bnews%5D=18&tx_news_pi1%5Bcontroller%5D=News&tx_news_pi1%5Baction%5D=detail&cHash=a6e542381e508c0501a09383cedc4d70.

So the id field of the news story field is included as a parameter.  We've tried making links by adjusting this parameter for the various Ids of different news stories, but each link allways returns the same news item.  So we are assuming that the hash value for each nwes story has to be calculated for each item to find the correct story.

Our question is.  Is it possible to build a unique URL for each story based on the information in the tx_news_domain_model_news table or is there a better way to create a JSON feed for each news story which includes the link to the original article.


Solution

  • You could define a special page rendering. either a new page or a new pagetype of an existing page.

    You use a page object and instead of the usual include of a template the whole content is generated by a CONTENT object. With this you select all news records and define a renderobject where you can use FLUIDTEMPLATE or build up the rendering in typoscript.

    In this way you can generate 'normal' URLs, which also might be niced by realurl.

    If you want to output other formats than HTML you propably need to escape string-delimiters in your texts and strings.
    Fluid templates may be a little bit complex if you have a format where whitespace is important. In typoscript whitespace can be handled with stdWrap.noTrimWrap