本文介绍了使用flux:field.inline.fal时如何获取fal对象而不是数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在助焊剂含量模板配置部分中,我定义了一个像这样的图像字段:

In my flux content template configuration section I define an image field like this:

<flux:field.inline.fal label="Image" name="images" maxItems="1" minItems="0" showThumbs="1"/>

在助焊剂含量模板的主要部分中,我调试输出:

In my flux content template main section I debug the output:

<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对象.

The debuging output shows an array but what I need is the FAL object of that image I added in the backend.

我在Google上搜索了很多,发现了2015年以来的一些较旧的帖子.所有人都说不可能让fal object(!)不断变化.还是这样吗?你知道吗?

I googled a lot and found some older posts from 2015. All say it is not possible to get the fal object(!) in flux. Is it still true? Do you know any way?

推荐答案

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

One solution is to create a custom ViewHelper:

<?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;
   }
}

这篇关于使用flux:field.inline.fal时如何获取fal对象而不是数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:00