使用vhs viewhelper "resource.record.fal“,我从页面资源中选择图像。这是非常好的工作,但我也想继承的图像,只要没有其他图像上传。有没有办法做到这一点?幻灯片属性对此视频对象不可用。我知道我可以用Typoscript完成所有这些工作,但是我想找到一个基于Fluid的解决方案。
下面是我的代码:
<v:resource.record.fal table="pages" field="media" uid="{data.uid}" as="resources" >
<f:for each="{resources}" as="resource">
<v:resource.image identifier="{resource.id}" />
</f:for>
发布于 2018-08-06 22:32:32
好了,下面是一些流畅的自由样式内联语法:
{v:page.rootLine()
-> v:iterator.column(columnKey: 'media', indexKey: 'uid')
-> v:iterator.filter(preserveKeys: 1)
-> v:iterator.keys()
-> v:iterator.last()
-> f:variable(name: 'firstPageUidWithMedia')}在步骤中:
media列值的子数组,使用列uid作为关键字>H110提取仅包含关键字的子数组
然后使用{firstPageUidWithMedia}而不是{data.uid}。
发布于 2020-04-21 03:44:48
我正在努力将Typo3从6.2LTS升级到9.5LTS,我发现fluidcontent将继续使用,现在下面的代码用于预览Flux内容中的图像。
我已经替换了我的旧代码:
<f:for each="{v:content.resources.fal(field: 'teaserImage')}" as="image">
<img src="{f:uri.image(src:'{image.id}',maxWidth:'64',treatIdAsReference:'1')}" alt="{image.alternative}"/>
</f:for>到下面的新代码:
<v:content.resources.fal field="teaserImage" as="images" record="{record}">
<f:for each="{images}" as="image">
<f:if condition="{image}">
<f:image src="{image.id}" treatIdAsReference="1" maxWidth="100"/>
</f:if>
</f:for>
</v:content.resources.fal>发布于 2018-08-06 22:15:56
我开发了这个VH,它可以满足您的需求:
namespace Your\Vendor\ViewHelpers;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use TYPO3\CMS\Frontend\Page\PageRepository;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* View helper to get the first image of rootline.
*/
class RootlineFirstImageViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* {@inheritdoc}
*/
public function initializeArguments()
{
$this->registerArgument('pid', 'int', '', true);
}
/**
* {@inheritdoc}
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): ?File {
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$pages = GeneralUtility::makeInstance(PageRepository::class)->getRootLine($arguments['pid']);
$files = [];
foreach ($pages as $page) {
/** @var FileReference[] $files */
$files = $fileRepository->findByRelation('pages', 'media', $page['uid']);
if (!empty($files)) {
break;
}
}
// It would be nice to have an extra argument to get a random image of the array.
return !empty($files) ? $files[0]->getOriginalFile() : null;
}
}然后,可以在流体模板中这样调用它:
<f:variable name="rootlineFirstImage"><whatever:rootlineFirstImage pid="{data.uid}"/></f:variable>
<f:if condition="{rootlineFirstImage}">
<f:image image="{rootlineFirstImage}" width="1280"/>
</f:if>https://stackoverflow.com/questions/51709471
复制相似问题