# Handlebars.js - Show data only if {{ image\_url }} doesn't contain "questionmark"

**URL:** https://forum.kirupa.com/t/handlebars-js-show-data-only-if-image-url-doesnt-contain-questionmark/638465
**Category:** web dev
**Created:** [July 5, 2018, 12:56pm UTC](https://forum.kirupa.com/t/handlebars-js-show-data-only-if-image-url-doesnt-contain-questionmark/638465 "2018-07-05T12:56:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kayut](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@kayut](https://forum.kirupa.com/u/kayut)
#### Post date: [July 5, 2018, 12:56pm UTC](https://forum.kirupa.com/t/handlebars-js-show-data-only-if-image-url-doesnt-contain-questionmark/638465/1 "2018-07-05T12:56:16Z")

</div>

Hi,

As you can see in this example, which I created on Codepen, some of the data don’t have an image and whenever there’s no image, a place holder image is shown:

[Handlebars.js Example](https://codepen.io/itsthomas/pen/WyBazO)

Is there any way in Handlebars.js to say that show the data only if the {{ image\_url }} doesn’t contain “questionmark”?

Something similar to this?

```auto
{{#each this}}
{{#if image_url !contains "questionmark"}}

    <li class='list-container'>
      <div class="image-container">
          <img src="{{ image_url }}">
      </div>
      <div class="name-container">
        {{ name }}
      </div>
      <div class='role-container'>{{{ role }}}</div>
    </li>

{{/if}}
{{/each}}
```

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [July 5, 2018, 1:08pm UTC](https://forum.kirupa.com/t/handlebars-js-show-data-only-if-image-url-doesnt-contain-questionmark/638465/2 "2018-07-05T13:08:41Z")

</div>

I don’t think handlebars allows anything beyond checking value/existence of variables in if template blocks.

If you want to do more complicated things, you’ll generally want to do that in the template data before you run it through the template. In your case, do the “questionmark” check in JavaScript, then put that result in your template data as something like data.noQuestionMark. Then in the template use

```auto
{{#if noQuestionMark}}
...

```

---

<div class="post-metadata">

### Author: ![kayut](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@kayut](https://forum.kirupa.com/u/kayut)
#### Post date: [July 5, 2018, 6:59pm UTC](https://forum.kirupa.com/t/handlebars-js-show-data-only-if-image-url-doesnt-contain-questionmark/638465/3 "2018-07-05T18:59:45Z")

</div>

I couldn’t find any solution with Handlebars.js, so I fixed it via pure JS:

```auto
(function removeNoImage() {
  for(let key in data.staff) {
    if(data.staff[key].image_url.indexOf('questionmark') !== -1) {
      delete data.staff[key];
    }
  }
})();
```
