Typo3 News use first image of news as hero on page outside of the extension

70 Views Asked by At

I'm trying to get an image of a news in the detail view. I'd like to use it in another section of my layout. I would need it outside the news extension. So I tried:

7 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
        7 {
           if.isTrue.data = GP:tx_news_pi1|news
           references {
              table = tx_news_domain_model_news
              fieldName = fal_media
              uid.data = GP:tx_news_pi1|news
           }
           sorting = datetime
           sorting.direction = descending
           as = news_images
        }

But unfortunately news_images is always empty, but the following returns me an url:

lib.newsimage = FILES
lib.newsimage {
if.isTrue.data = GP:tx_news_pi1|news
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
}

}

Why is the news_images empty but the url can be found?

2

There are 2 best solutions below

0
Julian Hofmann On BEST ANSWER

For FilesProcessor, there is no uid-property. data as part of stdWrap has to be applied directly on references.

So, this should do the job:

7 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
7 {
   if.isTrue.data = GP:tx_news_pi1|news
   references {
      table = tx_news_domain_model_news
      fieldName = fal_media
      // vvvv
      data = GP:tx_news_pi1|news
      // ^^^^
   }
   sorting = datetime
   sorting.direction = descending
   as = news_images
}

TS reference: https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/ContentObjects/Fluidtemplate/DataProcessing/FilesProcessor.html?#filesprocessor-stdwrap-on-references

1
Melanie Ganz On

I had a similar problem and used the DatabaseQueryProcessor and the FileProcessor:

6 = database-query
6 {
    table = tx_news_domain_model_news
    pidInList = 1
    where.data = GP:tx_news_pi1|news
    where.wrap = uid=|

    as = news_images

    dataProcessing {
        7 = files
        7 {
            if.isTrue.data = GP:tx_news_pi1|news
            references {
                table = tx_news_domain_model_news
                fieldName = fal_media
            }
        }
    }
}

The pidInList value has to be the id of your storage for news records. With this, you get the data of your current news record and the image as FileReference.