简体   繁体   中英

Use cropped image with fallback in TypoScript in TYPO3 8

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM