codeFareith codeFareith - 4 months ago 44
PHP Question

News Widget from EXT:news

Last week I started with TYPO3 and now I have to make an extension (widget) for a Dashboard plugin (where in the FE the User can select from a list of specific widgets and place them on this Dashboard).

The widget should be able to display the latest 5 of all news and (via dropdown) be able to show only the latest 5 news of a specific category.

For the News we're using EXT:news.

And that's where I'm stuck now.

In my custom extension, how can I access the deserved data (title, category and body) from the news-extension to pass it into my template?


This is pretty easy to do as you can completly reuse the NewsDemand object for filtering. An example looks like this:

    $newsRepository = $this->objectManager->get(NewsRepository::class);
    $demand = $this->objectManager->get(NewsDemand::class);
    $demand->setCategories(['12', '34']);
    $items = $newsRepository->findDemanded($demand);
    $this->view->assign('items', $items);

Take a look at the NewsRepository which handles all the possibilities of the demand object.