Search code examples
javascriptjquerydust.js

Check for null or empty value in placeholder text


I have a dust.js template that renders inputs based on a hash I am getting from the server. My hangup is that if the hash is empty I still get an input box rendered with an empty placeholder value, how can I check if the placeholder value is null and then hide that box?

<div class='criteria-input'>
  <input type='text' placeholder='{attribute}' value='{value}' size='20'/>
  <span class="close">X</span>
</div>

Solution

  • See the "Special Sections" documentation of dust.js here: http://akdubya.github.io/dustjs/#guide

    The "exists" syntax is what you want, so that you can do this:

    {?attribute}
    <div class='criteria-input'>
      <input type='text' placeholder='{attribute}' value='{value}' size='20'/>
      <span class="close">X</span>
    </div>
    {/attribute}