【问题标题】:Render image in fluid template if it exists?如果存在,在流体模板中渲染图像?
【发布时间】:2019-10-15 21:36:43
【问题描述】:

如何在尝试渲染之前使用f:if查看图像是否存在?

我尝试了以下方法但没有成功:

{f:if(condition: page.files.0, then: ' style="background-image:url({f:uri.image(image:page.files.0, width:300c, height:200c)}"')}

<f:if condition="{page.files.0}">
    style="background-image:url({f:uri.image(image:page.files.0, width:300c, height:200c)}"
</f:if>

如果有图像,它会起作用,但在没有图像时会破坏元素。

【问题讨论】:

    标签: typo3 fluid typo3-9.x fluid-styled-content


    【解决方案1】:

    当我想在 style 属性中添加图片 url 时,我通常会这样做:

    <f:if condition="{page.files.0}">
        <f:variable name="imageUri" value="{f:uri.image(
            image: page.files.0,
            width: '300c',
            height: '200c')}"/>
    </f:if>
    
    <div style="background-image: url('{imageUri}');">
       ...
    </div>
    

    如果图像不存在,那只会将其留空。虽然我经常遇到“其他”情况,但我使用我的自定义视图助手之一来生成占位符图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      • 2016-06-07
      相关资源
      最近更新 更多