0

the following typoscript searches a random subpage and renders the first image which is referenced in the media field. It works. But i need a default image when the media field is empty.

page.10 = COA_INT
page.10 {
  10 = CONTENT
  10 {
    table = pages
    select {
      orderBy = rand()
      max = 1
      pidInList = 34
    }

    renderObj = COA
    renderObj {

      5 = FILES 
      5 {
        references {
          table = pages
          uid.data = current:uid
          fieldName = media
        }
        begin = 0
        maxItems = 1
        renderObj = IMAGE
        renderObj {
          file.import.data = file:current:publicUrl
        }
      }
    }
  }
}

I tried with

file = fileadmin/....
file.import.data = file:current:publicUrl
file.treatIdAsReference = 1

or

file.import.ifEmpty = fileadmin/....

or whith override but it seems that the whole FILES-Object is empty when there is no file in field media and so ifEmpty is not reached.

Can anybody give me a hint?

Edit: TYPO3 6.2

andreas
  • 16,357
  • 12
  • 72
  • 76
lisardo
  • 1,322
  • 16
  • 31
  • I would move the `override` one level up to the first `renderObj`. – pgampe Sep 15 '16 at 20:24
  • This hint took me on the right path. I was able to solve my problem yet. – lisardo Sep 15 '16 at 20:47
  • Just as a side-note: ` renderObj { file.import.data = file:current:publicUrl file.treatIdAsReference = 1 } ` can be optimized like ` renderObj { file.import.data = file:current:originalUid // file:current:uid } ` It is also possible to use the alt + title from the sys_file_reference ` titleText.data = file:current:title // file:current:alternative altText.data = file:current:alternative // file:current:title ` – minifranske Sep 16 '16 at 12:04
  • Right - when using file:current:publicUrl then treatIdAsReference is not necessary - only when using file:current:uid (not: file:current:originalUid - thats wrong.) I corrected my post. – lisardo Sep 16 '16 at 20:28

1 Answers1

1

pgampe gave me the right hint - override or ifEmpty have to start one level up:

5.stdWrap.ifEmpty.cObject = IMAGE
5.stdWrap.ifEmpty.cObject {
      file = fileadmin/ .....
      file.height = 200c
      file.width  = 200c
}
andreas
  • 16,357
  • 12
  • 72
  • 76
lisardo
  • 1,322
  • 16
  • 31