typo3 - TYPO3 7.6 中响应式图像的附加源集合

标签 typo3 typoscript responsive typo3-7.6.x

是否可以实现额外的 sourceCollection 代码来在扩展中呈现响应式图像。我已经配置了标准 tt_content.image.20.1.sourceCollection 的代码,并且工作正常。

这是我的 TypoScript 代码:

tt_content.image.20.1.layout {
  srcset {
    element.wrap = <img src="###SRC###" srcset="###SRC### ###WIDTH###w,###SOURCECOLLECTION###" sizes="|"###PARAMS######ALTPARAMS######SELFCLOSINGTAGSLASH###>
    element = (min-width: 1020px) 800px, (min-width: 740px) 460px, calc(100vw - 20px)
  }
}

    tt_content.image.20.1.sourceCollection >
    tt_content.image.20.1.sourceCollection {
      tiny {
        width = 160
        maxW < .width
        srcsetCandidate = 160w
      }
      extrasmall {
        width = 320
        maxW < .width
        srcsetCandidate = 320w
      }
      small {
        width = 460
        maxW < .width
        srcsetCandidate = 460w
      }
      normal {
        width = 600
        maxW < .width
        srcsetCandidate = 600w
      }
      medium {
        width = 780
        maxW < .width
        srcsetCandidate = 780w
        quality = 60
      }
      large {
        width = 920
        maxW < .width
        srcsetCandidate = 920w
        quality = 60
      }
      extralarge {
        width = 1100
        maxW < .width
        srcsetCandidate = 1100w
        quality = 60
      }
      huge {
        width = 1200
        maxW < .width
        srcsetCandidate = 1200w
        quality = 60
      }
    }


lib.responsiveImage {
    default = IMAGE
    default {
        file.import.current = 1
        altText.data = field:altText
        titleText.data = field:titleText
        layoutKey = srcset
        layout.srcset < tt_content.image.20.1.layout.srcset
        sourceCollection < tt_content.image.20.1.sourceCollection
    }
    specialBig < .default
    specialBig {
        layoutKey = srcset
        layout.srcset {
            element.wrap = <img src="###SRC###" srcset="###SRC### ###WIDTH###w,###SOURCECOLLECTION###" sizes="|"###PARAMS######ALTPARAMS######SELFCLOSINGTAGSLASH###>
            element = (min-width: 1020px) 521px, (min-width: 740px) 460px, calc(100vw - 20px)
        }

        sourceCollection { 
          tiny {
          width = 160
          maxW < .width
          srcsetCandidate = 160w
          }
          extrasmall {
          width = 320
          maxW < .width
          srcsetCandidate = 320w
          }
          small {
          width = 460
          maxW < .width
          srcsetCandidate = 460w
          }
          normal {
          width = 600
          maxW < .width
          srcsetCandidate = 600w
          }
          medium {
          width = 460
          maxW < .width
          srcsetCandidate = 780w
          quality = 60
          }
          large {
          width = 460
          maxW < .width
          srcsetCandidate = 920w
          quality = 60
          }
          extralarge {
          width = 520
          maxW < .width
          srcsetCandidate = 1100w
          quality = 60
          }
          huge {
          width = 600
          maxW < .width
          srcsetCandidate = 1200w
          quality = 60
          }
        }
    }
} 

FluidTemplate部分:

<f:cObject typoscriptObjectPath="lib.responsiveImage.default" data="{image.uid}"></f:cObject>
<f:cObject typoscriptObjectPath="lib.responsiveImage.specialBig" data="{image.uid}"></f:cObject>

来自 lib.responsiveImage.default 部分的图像渲染正确,但来自 lib.responsiveImage.specialBig 的整个 sourceCollection 被忽略并在输出我只有:

<img src="fileadmin/img/img.jpg" srcset="fileadmin/img/img.jpg 800w," sizes="(min-width: 1020px) 521px, (min-width: 740px) 460px, calc(100vw - 20px)" alt="alt-text" title="title-text">

最佳答案

如果可以的话,在流体模板中执行此操作会更容易。

您可以编写自己的 ViewHelper 或插件,并用您的图像数据提供它,然后使用如下所示构建您的图像:

<picture>
     <f:for each="{sizes}" as="size">
         <source media="(min-width: {...}px)" 
                 srcset="{f:uri.image(...)}">
     </f:for>
     <img src="{f:uri.image(...)}" alt="{...}" title="{...}">
 </picture>

关于typo3 - TYPO3 7.6 中响应式图像的附加源集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41185447/

相关文章:

css - 响应式 YouTube 嵌入视频设置为特定尺寸,无黑边框

html - 响应式导航栏的缩放问题

typo3 - 扩展无法覆盖默认(回退)templateRootPaths/partialRootPaths/LayoutRootPaths

typo3 - 发生验证错误时操作的参数丢失

tomcat - Typo3 Solr,如何设置 solr 5.X

typo3 - 如何在 Typoscript 中获取页面类别(并与 tx_news 一起使用)

typo3 - 如何对每个菜单项应用不同的包装?

html - 缩小窗口大小时防止家谱破裂

typo3 - 如何从 Typo3 中的文件中读取行?

typo3 - TypoScript 会在 TYPO3 中被 YAML 取代吗