TYPO3 (with extbase) fluid: 用绝对路径显示图片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"/>
其中returns出现以下错误:
Argument "absolute" was not registered.
我也尝试了 f:uri.resource ,它适用于 image1,但当然不适用于 image2,因为没有 extensionName。
有什么提示吗?
f:uri.image
视图助手的 absolute
参数是最近才在 TYPO3 7.6.0 中添加的。见 changelog:
Feature: #64286 - Added absolute url option to uri.image and image viewHelper
The ImageViewhelper and Uri/ImageViewHelper got a new option absolute. With this option you are able to force the ViewHelpers to output an absolute 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;
}
}
对于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"/>
其中returns出现以下错误:
Argument "absolute" was not registered.
我也尝试了 f:uri.resource ,它适用于 image1,但当然不适用于 image2,因为没有 extensionName。
有什么提示吗?
f:uri.image
视图助手的 absolute
参数是最近才在 TYPO3 7.6.0 中添加的。见 changelog:
Feature: #64286 - Added absolute url option to uri.image and image viewHelper
The ImageViewhelper and Uri/ImageViewHelper got a new option absolute. With this option you are able to force the ViewHelpers to output an absolute 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;
}
}