View Full Version : Handlebars.js - Show data only if {{ image_url}} doesn't contain "questionmark"

07-05-2018, 12:55 PM

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 like this?

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

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


07-05-2018, 07:04 PM
I couldn't find any solution with Handlebars.js, so I did it in JavaScript

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