handlebars.js - Handlebars block helper "if" doesn't work -


i'm making movie search based on data i'm getting rotten tomatoes api. i'm using handlebars.js. far i've got template , works fine.

    <div class="info">         <h3>{{title}}</h3>         <span> year: {{year}} </span>         <span> studio:{{studio}} </span>          <span> synopsis:{{synopsis}} <span>     </div> 

however, of of movies don't have studio provided i'd make in case no "studio:" printed. code so:

   {{#if studio}}      <span> studio:{{studio}} </span>     {{/if}} 

i've copied example provided on handebars.js page. still doesn't work. explain me i'm missing? suppose there no need use handlebars.registerhelper since i'm using simple if statement. or it?

see jsfiddle. should not have issue that.

from documentation.

you can use if helper conditionally render block. if argument returns false, undefined, null, "" or [] (a "falsy" value), handlebars not render block.

so check 'studio' value.

code have fiddled.

html:

<p>{{name1}}</p>  {{#if name2}}    <p>{{name2}}</p>     {{/if}} <p>end</p> 

js:

this.$el.html(temp({name1: 'stack'})); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -