Embedding presentation logic

Of course, there's a lot more that you can do than just this! Handlebars also supports conditional statements:

    let model = { 
      name: 'World', 
      description: 'This will only appear because its set.' 
    }; 
  
    <div> 
       Hello {{ name }}!<br/><br/> 
      {{#if description}} 
         <p>{{description}}</p> 
      {{/if}} 
    </div> 

Using an if block helper, as shown in the preceding code, you can check for true conditionals and only display HTML and/or data if the condition is true. Alternatively, you can use the unless helper to do the opposite and display HTML only if a condition is false:

    let model = { 
      name: 'World' 
    }; 
 
    <div> 
       Hello {{ name }}!<br/><br/> 
      {{#unless description}} 
         <p>NOTE: no description found.</p> 
      {{/if}} 
    </div> 

You can use both if and else as well as unless the same way you would use conditional if/else in other programming languages. So that's it! These were all the basics that we need to know to resume our application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.186.178