在 TYPO3 8 中的 TypoScript 中使用带有后备的裁剪图像 [英] Use cropped image with fallback in TypoScript in TYPO3 8

查看:42
本文介绍了在 TYPO3 8 中的 TypoScript 中使用带有后备的裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此 TS 代码始终生成 600x400 像素的图像:

This TS code always produces a 600x400px image:

  10 = FILES
  10 {
      required = 1
      references {
        table = tt_content
        fieldName = image
      }
      renderObj = IMAGE
      renderObj {
        wrap = <div class="teaser-image">|</div>
        file.import.data = file:current:originalUid // file:current:uid
        file.crop.data = file:current:crop
        file.width=600c
        file.height=400c
      }
  }

如果我删除

      file.width=600c
      file.height=400c

然后将使用来自裁剪向导的裁剪图像.

then the cropped image from the crop wizard will be used.

但我需要两者(它是现有站点的升级):如果可用,则使用裁剪的图像,但如果没有,则使用给定的高度和宽度.

But I need both (it's an upgrade of an existing site): if available, the cropped image is used, but if not, the given height and width are used.

如何使用file:current:crop"部分来覆盖宽度&只有给定的高度?或者我如何设置回退?像……

How do I use the "file:current:crop" part to override width & height only if given? Or how do I set a fallback? something like...

file.crop.data = file:current:crop // fallback...

推荐答案

我已移至 renderObj 中的 FLUIDTEMPLATE:

I've moved to FLUIDTEMPLATE in the renderObj:

renderObj = FLUIDTEMPLATE
renderObj {
  file = path/to/templates/content/teaser.html
  dataProcessing {
    10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
    10 {
      references.fieldName = image
      references.table = tt_content
      as = teaserimages
    }
  }
}

(需要文件处理器)

然后在模板中

<img src="<f:uri.image image="{teaserimages.0}" width="600c" height="400c" />

表现符合预期

这篇关于在 TYPO3 8 中的 TypoScript 中使用带有后备的裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆