Use cropped image with fallback in TypoScript in TYPO3 8

爷,独闯天下 提交于 2019-12-25 01:45:02

问题


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

If I remove

      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.

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

回答1:


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

(The FilesProcessor is required)

And then in the template

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

Behaves as expected



来源:https://stackoverflow.com/questions/48584655/use-cropped-image-with-fallback-in-typoscript-in-typo3-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!