用后备覆盖 FILES references.data

Override FILES references.data with fallback

我通过 data = level media:-1,slide 获取滑块的图像 在新闻单页上,我想使用新闻图片代替。所以我将代码放在条件 [globalVar = GP:tx_news_pi1|news > 0] 中并获取新闻图像。一切都好。但是如果没有新闻图像,我想展示水平媒体。我该怎么做?

这是 TypoScript:

lib.keyVisual = COA
lib.keyVisual {
    10 = FILES
    10 {
        references {
            data = levelmedia:-1,slide
        }

        renderObj = COA
        renderObj.10 = IMAGE
        renderObj.10 {
            file {
                import.data = file:current:uid
                treatIdAsReference = 1
                width = {$keyVisualWidth}
                #width.field >
                height = {$keyVisualHeight}

            }
        }

        renderObj.20 = COA
        renderObj.20 {
            1 = TEXT
            1 {
                data = file:current:title
                required = 1
                wrap = <h3>|</h3>
            }
            2 = TEXT
            2 {
                data = file:current:description
                required = 1
                wrap = <p>|</p>
            }
            stdWrap.wrap = <div class="imageCaptionBox">|</div>
            stdWrap.required = 1
        }

        renderObj.wrap = <li>|</li>
    }
    wrap = <section id="keyvisual" class="keyvisual fullWidth"><ul class="slider nav">|</ul></section>
}
[globalVar = GP:tx_news_pi1|news > 0]
    lib.keyVisual {
        10 {
            references {
                data >
                table = tx_news_domain_model_news
                uid.data = GP:tx_news_pi1|news
                fieldName = fal_media
            }

            # only images with showinpreview
            renderObj.if {
                value = 1
                equals.data = file:current:showinpreview
            }
        }
    }
[global]

所有条件都有一个[else]所以你不需要重新定义。

[globalVar = GP:tx_news_pi1|news > 0]
lib.keyVisual {
     ... from news...
}
[else]
lib.keyVisual {
    ... from levelmedia ...
}
[global]

那么你需要区分图片是否可用于新闻。

[globalVar = GP:tx_news_pi1|news > 0]
lib.keyVisual = COA
lib.keyVisual {
     10 = CONTENT
     10 {
        // get news record and then get file
        ... from news...
        if.empty.field = media
     }
     20 = FILES
     20 {
        ... from levelmedia ...
        if {
           empty.field = media
           negate = 1
        }
     }
}
[else]
lib.keyVisual {
    ... from levelmedia ...
}
[global]

可以通过为被复制的关卡媒体使用使用临时对象来优化。

temp.levelmediaImage {
    ...
}
[globalVar = GP:tx_news_pi1|news > 0]
kib.keyVisual = COA
lib.keyVisual {
     10 = CONTENT
     10 {
        // get news record and then get file
        ... from news...
        if.empty.field = media
     }
     20 < temp.levelmediaImage
     20 {
        if {
           empty.field = media
           negate = 1
        }
     }
}
[else]
lib.keyVisual < temp.levelmediaImage
[global]

使用 ifEmpty stdWrap 选项。

如果您的 COA 为空,您可以使用此选项渲染默认图像。

简单举例说明:

[globalVar = GP:tx_news_pi1|news > 0]
  lib.keyVisual {
    stdWrap.ifEmpty.cObject < .10

    #overrides for news picture
    10 {
      ...
    }
  }
[global]