首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在使用flux:field.inline.fal时获取fal对象而不是数组

如何在使用flux:field.inline.fal时获取fal对象而不是数组
EN

Stack Overflow用户
提问于 2018-06-26 02:49:25
回答 1查看 267关注 0票数 0

在我的flux内容模板配置部分,我定义了一个图像字段,如下所示:

代码语言:javascript
复制
<flux:field.inline.fal label="Image" name="images" maxItems="1" minItems="0" showThumbs="1"/>

在我的flux content template main部分,我调试输出:

代码语言:javascript
复制
<f:for each="{v:resource.record.fal(table: 'tt_content',field: 'images', uid: '{record.uid}')}" as="image" iteration="iterator">
  <f:debug>{image}</f:debug>
</f:for>

调试输出显示了一个数组,但我需要的是我在后端添加的图像的FAL对象。

我用谷歌搜索了很多,发现了一些2015年的老帖子。所有人都说不可能获取fal对象(!)在不断变化。这仍然是真的吗?你知道有什么方法吗?

EN

回答 1

Stack Overflow用户

发布于 2018-07-02 15:16:39

一种解决方案是创建自定义ViewHelper:

代码语言:javascript
复制
<?php

namespace Cmichael\Typo3projectprovider\ViewHelpers\Content;

/* FalViewHelper
* To get fal object by image uid (respectivly in flux templates)
* Usage example: <cm:content.fal referenceUid="{image.uid}">
* */

class FalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

  /**
   * @var bool
   */
   protected $escapeOutput = false;

  /**
   * Initialize arguments.
   *
   */
   public function initializeArguments() {
      $this->registerArgument('referenceUid', 'integer', 'File reference uid', true, 0);
   }

  /**
   * Return file reference
   *
   * @return \TYPO3\CMS\Core\Resource\FileReference|null
   */
   public function render() {
      $referenceUid = $this->arguments['referenceUid'];
      $fileReferenceData = $GLOBALS['TSFE']->sys_page->checkRecord('sys_file_reference', $referenceUid);
      return $fileReferenceData ? \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($referenceUid) : $referenceUid;
   }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51030082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档