Search code examples
typo3tx-news

Get tx_news fal_media via TypoScript to use in fluid page template


I want to use the first image out of a new entry to include in the page header. Therefore i need the news fal_media data in TypoScript to pass it to my page fluid template.

I managed to get the first image as a file path by this TypoScript code:

lib.newsimage = FILES
lib.newsimage {
    references {
        table = tx_news_domain_model_news
        uid.data = GP:tx_news_pi1|news
        fieldName = fal_media
    }
    maxItems = 1
    renderObj = IMG_RESOURCE
    renderObj.file {
        import.data = file:current:publicUrl
    }
    stdWrap.ifEmpty = {$settings.ext.news.imageDummy}
}

But is there a better way to do it, especially to get the data as an array of FileReferences? With a FAL FileReference i could also take crop an meta data into account.


Solution

  • You might use a FilesProcessor


    example based on the manual:

        10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
        10 {
           as = news_images
           references {
              fieldName = fal_media
              table = tx_news_domain_model_news
           }
           sorting = datetime
           sorting.direction = descending
        }
    

    Although I can't imagine that this will be the correct way as there is no guarantee that the first news you select by this is the first news shown on the page. News have multiple conditions to be shown aside of basic visibility: ordering by publishing time, archived state, top-news state, groups or categories, ...

    Maybe it would be easier if you use a news plugin with a special template and don't forget to enable showing of news multiple times (by default each news gets shown only once in a page)