skip to Main Content

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 }}" class="featured_image"></div>
{% endif %}
                   
{% if featured-image == blank %}
<div class="placeholder_image"></div>
{% endif %}

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

2

Answers


  1. Chosen as BEST ANSWER

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


  2. 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 }}" class="featured_image">
      </div>
    {% else %}
      <div class="placeholder_image"></div>
    {% endif %}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search