Inserting if statement inside ES6 template literal

You’ll need to move your logic into a function or use the ternary operator:

`${result['color 5'] ? 'color 5 exists!' : 'color 5 does not exist!'}`

Additional example based on comment:

`${result['color 5'] ? 
    `<div class="color" style=background-color:#${result['color 5']}><h6>${result['color 5']}</h6></div>` 
: ''}`

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)