TYPO3 tx_news扩展:取消勾选预览显示后前端仍展示图片的实现方案
Hey there! I’ve dealt with similar quirks in older TYPO3/news versions before, so let’s break down your options to get those images showing again:
1. Directly access the relation in Fluid (no extra extension needed)
Even when you uncheck "Show in preview views", the image relation data still lives in the database—it just doesn’t populate the default preview variables like news_image_intS. You can skip those preview variables entirely and access the raw image relation directly from the news item object in your Fluid template:
<f:if condition="{newsItem.news_image}"> <f:for each="{newsItem.news_image}" as="image"> <img src="{f:uri.image(image: image, width: '300c')}" alt="{image.alternative}" /> </f:for> </f:if>
Note: If you’ve customized the image field name in your news setup, replace news_image with your actual field label—this is the default name for the standard news extension.
This works because Fluid can pull properties directly from the domain object, bypassing the preview view restrictions that block variables like news_image_intS.
2. Force relation loading with TypoScript
If direct Fluid access doesn’t behave as expected (rare, but possible in older versions), you can use TypoScript to explicitly load the image relation alongside the news item. Add this to your site’s TypoScript setup:
plugin.tx_news { settings { persistence { classes { GeorgRinger\News\Domain\Model\News { properties { news_image { lazyLoading = 0 } } } } } } }
Disabling lazy loading here ensures the image relation is loaded immediately with the news item, making it available in your template without relying on preview variables.
3. Build a lightweight custom ViewHelper (for edge cases)
If the above methods fall short, a simple custom ViewHelper can fetch the images directly from the news item’s domain object. Here’s how to set it up:
- Create a ViewHelper class in your custom extension (e.g.,
Classes/ViewHelpers/GetNewsImagesViewHelper.php):
<?php namespace YourVendor\YourExtension\ViewHelpers; use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; use GeorgRinger\News\Domain\Model\News; class GetNewsImagesViewHelper extends AbstractViewHelper { /** * Fetch images from a news item * @param News $newsItem * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage */ public function render(News $newsItem) { return $newsItem->getNewsImage(); } }
- Use it in your Fluid template:
<f:if condition="{yourextension:getNewsImages(newsItem: newsItem)}"> <f:for each="{yourextension:getNewsImages(newsItem: newsItem)}" as="image"> <img src="{f:uri.image(image: image, width: '300c')}" alt="{image.alternative}" /> </f:for> </f:if>
4. Consider extension updates (if feasible)
While you’re on news v3.2.8, newer backported versions for TYPO3 6.2 might have smoother handling of preview view restrictions. If your site allows for safe updates, this could be a long-term fix—but it’s optional if the above solutions work for you.
内容的提问来源于stack exchange,提问作者schumiel

