Search code examples
typo3typo3-9.xtx-news

How to get second Image from Mediafile in News Extension? [TYPO3]


How can I get the second image in template for news extension of GeorgeRinger in TYPO3.

I extend the showinpreview field with "show in teaser" and I want to acces the second image, or better the image where "show in teaser" was set, in the templatefile for the teaser.

If I debug the newsItem.mediaPreviews, there ist only one image, but I set two in the backend… so how can I get the other image.

Thanks

TYPO3: 9.5.14 news: 7.3.1


Solution

  • If you check out the model News you will see this:

    public function getMediaPreviews()
    {
        $configuration = [FileReference::VIEW_LIST_AND_DETAIL, FileReference::VIEW_LIST_ONLY];
        return $this->getMediaItemsByConfiguration($configuration);
    }
    

    This means that you only get those with the allowed types.


    As a solution there are 2 options:

    • use {newsItem.getMedia} and check in the <f:for> for the value
    • extend the model with a custom getter method which returns the ones you need