簡體   English   中英

TYPO3(帶有extbase)流體:顯示具有絕對路徑的圖像src

[英]TYPO3 (with extbase) fluid: display image src with absolute path

對於XML導出,我需要輸出2張圖像的絕對路徑。 Image1位於/typo3conf/ext/app/Resources/Public/Images/image1.png,Image2位於/uploads/tx_extensionname/image2.png

對於我的一生,我找不到找到圖像絕對路徑的方法。 我試過的

<f:uri.image absolute="1" src="EXT:app/Resources/Public/Images/image1.png"/>

返回以下錯誤:

Argument "absolute" was not registered.

我也嘗試了f:uri.resource,它適用於image1,但是當然不適用於image2,因為沒有extensionName。

有什么提示嗎?

f:uri.image視圖幫助器的absolute參數是最近才在TYPO3 7.6.0中添加的。 請參閱更改日志

功能:#64286-向uri.image和image viewHelper添加了絕對URL選項

ImageViewhelper和Uri / ImageViewHelper獲得了一個新的絕對選項。 使用此選項,您可以強制ViewHelpers輸出絕對URL。

我建議升級到TYPO3 7.6

如果由於某種原因無法實現,則可以擴展f:uri.image視圖幫助器。 以下代碼未經測試,但應適用於6.2 LTS(我從7.6中的TYPO3\\CMS\\Extbase\\Service\\ImageService中借用了部分代碼):

namespace Vendor\ExtensionKey\ViewHelpers\Uri;

use TYPO3\CMS\Fluid\ViewHelpers\Uri\ImageViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ImageViewHelper extends ImageViewHelper
{
    public function render(
        $src = null,
        $image = null,
        $width = null,
        $height = null,
        $minWidth = null,
        $minHeight = null,
        $maxWidth = null,
        $maxHeight = null,
        $treatIdAsReference = false,
        $absolute = false
    ) {
        $uri = parent::render($src, $image, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight, $treatIdAsReference);

        if ($absolute) {
            $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
            $uri = GeneralUtility::locationHeaderUrl($uriPrefix . $uri);
        }

        return $uri;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM