TYPO3首先提供内容元素的图像

时间:2017-02-03 12:56:22

标签: image typo3

我想只显示列中不同内容元素的第一个可用图像。

以下代码向我展示了所有可用的图像,但我只需要第一个! 有人可以帮帮我吗?

lib.contentImage = CONTENT
lib.contentImage {
  wrap = |
  table = tt_content
  select {
    languageField = sys_language_uid
    where = colPos = 0
    orderBy = sorting
    pidInList = 32
  }
  renderObj = COA
  renderObj{
    wrap = <div class="item">|</div>
    10 = FILES
    10 {
        references {
            table = tt_content
            uid.data = uid
            fieldName = assets
        }
        renderObj = IMAGE
        renderObj {
            wrap = <div class="item-image">|</div>
            file.import.data = file:current:originalUid
            file.width = 1920c
            file.height = 600c
        }
    }
  }
}

3 个答案:

答案 0 :(得分:1)

您可以尝试使用LOAD_REGISTER

例如:(未经测试)

lib.contentImage = COA
lib.contentImage {
  5 = LOAD_REGISTER
  5.imageRendered = 0

  10 = CONTENT
  10 {
    wrap = |
    table = tt_content
    select {
      languageField = sys_language_uid
      where = colPos = 0
      orderBy = sorting
      pidInList = 32
    }
    renderObj = COA
    renderObj{
      wrap = <div class="item">|</div>
      10 = FILES
      10 {
        references {
          table = tt_content
          uid.data = uid
          fieldName = assets
        }

        max = 1

        renderObj = COA
        renderObj {
          stdWrap.if.isFalse.data = register:imageRendered

          5 = LOAD_REGISTER
          5.imageRendered = 1

          10 = IMAGE
          10 {
            wrap = <div class="item-image">|</div>
            file.import.data = file:current:originalUid
            file.width = 1920c
            file.height = 600c
          }
        }
      }
    }
  }

  99 = RESTORE_REGISTER
}

答案 1 :(得分:1)

我用它来获取页面上第一张图片的网址,以获取打开的图形标记。

page.meta.og:image.cObject = CONTENT
page.meta.og:image.cObject {
    table = tt_content
    select {
        where = (colPos = 0 AND image != 0 )
        selectFields = uid
        orderBy = sorting
        max = 1
    }
    renderObj = COA
    renderObj {
        1 = TEXT
        1 {
            cObject = FILES
            cObject {
                references {
                    table = tt_content
                    uid.field = uid
                    fieldName = image
                }
                maxItems = 1
                renderObj = TEXT
                renderObj {
                    typolink.parameter.data = file:current:publicUrl
                    typolink.forceAbsoluteUrl = 1
                    typolink.returnLast = url
                }
            }
        }
    }
}

答案 2 :(得分:0)

您是否需要每个Contentelement中的第一个或所有Contentelements的第一张图片?

如果您只想为每个元素添加一个图像,则可以在FILES对象https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Files/Index.html#usage-with-references中设置maxItems