【问题标题】:TYPO3 (with extbase) fluid: display image src with absolute pathTYPO3 (with extbase) fluid: 用绝对路径显示图片src
【发布时间】:2016-01-13 13:45:24
【问题描述】:

对于 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。

有什么提示吗?

【问题讨论】:

    标签: php typo3 fluid extbase


    【解决方案1】:

    f:uri.image 视图助手的 absolute 参数是最近才在 TYPO3 7.6.0 中添加的。见changelog

    功能:#64286 - 为 uri.image 和 image viewHelper 添加了绝对 url 选项

    ImageViewhelper 和 Uri/ImageViewHelper 获得了一个新选项 absolute。使用此选项,您可以强制 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;
        }
    }
    

    【讨论】:

    • 好的,非常感谢!不幸的是,现在更新不是一个选项,但我会实现你对 f:uri.image 的扩展
    • @Chi,只是出于好奇,这个解决方案对你有用吗?我的回答有什么可以/应该改进的地方吗?
    • 我实际上尝试了您的解决方案 - 但在我的情况下,我未能使 viewhelper 在 Typo3 6.2 中工作。 - 它甚至不会加载(参数“absolute”未注册。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    • 1970-01-01
    相关资源
    最近更新 更多