如果内容字段为空显示 none

If content field is empty display none

我正在尝试使用 Bolt / Twig 编写 CMS。不是很熟悉,所以需要一点帮助。

在一个页面上应该有一张包含 link 的图片。但是如果contentlink或者image是空的应该显示none。 所以我写道:

{% if record.contentlink %} 
  <a href="{{ record.contentlink }}">
     {% if record.image!="" %}
        <img src="{{ image(record.image, 672, 448) }}">
  {% endif %}</a>
{% endif %}

{% if contentlink is empty %}
   <a class="none"></a>
{% endif %}

CSS 就是:

.none {
display: none;
}

问题是,如果 contentlink 为空,则会在 link 所在的位置显示一个小框:

Like this

有什么建议吗?

我想我实际上找到了更好的方法。刚用过:

{% if record.contentlink is not empty %} 

然后做了一个partial to include。