Sunday, February 16

Using Handlebars

Lets say I have a json data file which i want to display on the website.

{
    "articles": [
 
        {
            "headline": "Both Knees replaced at one go.",
            "body" : [ "<p>First sentence</p>", "<p>Second Sentence</p>"]
        }
    ]
}

My Main html file will have the below code

<script id="articles-template" type="text/x-handlebars-template">
          <article>
          {{#articles}}
            <h2 class="text-center">{{headline}}</h2>
          {{#each body}}
             {{{this}}} 
          {{/each}}
          {{/article}}
          </article>
</script> 

My Javascript file will have this code.

$(document).ready(function(){
   PRESS_RELEASE.loadArticles(); 
});
var PRESS_RELEASE ={
  handlerData:function(resJSON){
      var templateSource = $("#articles-template").html(),
          template = Handlebars.compile(templateSource),
          articleHTML = template(resJSON);
       $('#articles').html(articleHTML);
  },
  loadArticles : function(){
      $.ajax({
          url:"assets/data/press-releases.json",
          method:'get',
          success: this.handlerData
      });
  }
};


Of course you need to include the handlebars.js file and jquery file in your html. 

Monday, February 10

Subway - Awesome

Last week It was time to try subway. I had tried McDonald’s and KFC several times earlier but never got a chance to try subway.

Being my first time there, I choose to try there very basic roll or “sub” as they call it. After a quick look around, I decided to settle with chicken seekh sub.

So the ingredients were very basic, 2 pieces of chicken seekh followed by tomato, cabbage, potato and cucumber. Nothing fascinating. However, before preparing the “sub”, the attendant asked me for my choice of bread. I wanted to try multigrain bread (I’ve tasted brown bread and white bread), so multigrain it was. Then came the choice for sauce. I wanted to try mixture of all the sauce.

 

It was very fascinating to see the chef prepare the sub for you and you have control over what goes where.

 

I then settled down with my tray, unwrapped the sub, it was huge by the way, and then took the first bite. Amazing. Not the ingredients, but the bread. The bread was neither crisp nor soft, just perfect. The taste was awesome. I just loved every bite of it.

 

I just wished I had my own bakery or at least an oven to so that I can bake my own bread. One day, I shall definitely get myself an oven. Just after I get a barbeque. Yup, the foodie in me wants to try all the possible dishes in this world, so does the chef in me wants to be able to cook my own bread. One day.