Home > Enterprise >  Liquid Hide Featured image and show placeholder
Liquid Hide Featured image and show placeholder

Time:01-04

I want to show my featured image when its set, but when its not set I want to hide the featured image and show a placeholder that I have defined.

{% if featured-image != blank %}
<div><img src="{{ article | img_url: 'master' }}" loading="lazy" alt="{{ article.alt }}" ></div>
{% endif %}
                   
{% if featured-image == blank %}
<div ></div>
{% endif %}

Currently its always showing the placeholder, even if the article has a featured image.

CodePudding user response:

One thing that jumps out at me is 'featured-image'. Usually schema ID's will use underscores, not hyphens. It might help to post that part of your schema code to see if there's anything wrong there.

Checking the CLI for any errors might help as well (if you're using the CLI).

Another thing you could do is use an {% else %} tag, instead of two IF tags, which will clean things up a bit.

{% if featured-image != blank %}
  <div>
    <img src="{{ article | img_url: 'master' }}" loading="lazy" alt="{{ article.alt }}" >
  </div>
{% else %}
  <div ></div>
{% endif %}

CodePudding user response:

As mentioned earlier by @ComicsDansMS, this was the mistake. And also it should look like this: {% if article.image != blank %}

  • Related