【问题标题】:Apostrophe cms : widget html template check if image is set撇号 cms:小部件 html 模板检查是否设置了图像
【发布时间】:2017-05-10 02:36:14
【问题描述】:

在 Apostrophe CMS 中,如何检查模板中是否设置了图像?

例如,如果我有一个“标题”字段, {% if data.widget.title %} 工作正常。

但是,对于图像,设置如下: {{ apos.singleton(data.widget, 'image', 'apostrophe-images', {}) }} 相同的模式不起作用,因为data.widget.image 始终是[object][object]'

我做了一些阅读并发现图像的传递方式不同,因为它们是pieces 的一部分,但无法使其正常工作。有什么想法吗?

【问题讨论】:

    标签: apostrophe-cms


    【解决方案1】:

    如果您的图像字段只处理单个图像:

    {% set image = apos.images.first(data.widget.image) %}
    {% if image %}
      ...
    {% endif %}
    

    如果你需要一些基于数组中图像数量的逻辑,你也可以使用apos.images.all

    {%- set images = apos.images.all(data.widget.slideshow) -%}
    {% if (images.length > 1) %}
      ...
    {% endif %}
    

    There's an example of this logic in this bit of documentation as well.

    【讨论】:

    • (这是答案,只是不确定如何接受等)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多