Aessandro
Aessandro

Reputation: 5761

Handlebars.js beginning

I am new to handlebars.js and I started to play around with it. However I am already stuck could you please explain what I am doing wrong?

This is in the head tag:

 <script id="header" type="text/x-handlebars-template">
  <div> {{ headerTitle }} </div>
  Today is {{weekDay}}
 </script>

and this in the body:

<script>

      var theData = {headerTitle:"Shop Page", weekDay:"Wednesday"};


    
  var theTemplateScript = $("#header").html();



      var theTemplate = Handlebars.compile (theTemplateScript);


      
$(document).append (theTemplate (theData));

 </script>

The page suppose to return the following:

Shop Page Today is Wednesday

Upvotes: 0

Views: 127

Answers (1)

Ledhund
Ledhund

Reputation: 1236

The template works, you just need to append the generated markup to an element.

$("body").append(theTemplate(theData));

Upvotes: 1

Related Questions