S
S
Stepan2014-08-12 06:56:51
JavaScript
Stepan, 2014-08-12 06:56:51

Why doesn't handlebars work?

<ul class="updates">
    <script id="template" type="text/x-handlebars-template">
        <li>
            <h2>{{name}}</h2>
        </li>
    </script>
</ul>


<script src="js/jquery-1.11.1.js"></script>
<script src="js/handlebars-v1.3.0.js"></script>


<script type="text/javascript">

    $(document).ready(function () {

        var template = Handlebars.compile( $('#template').html() );
        $('.updates').append( template(data) );

        var data = {
            name: 'Jane Doe'
        }
    });
</script>

Does not work although I take everything as in the example

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2014-08-12
@xoma2

Your data variable is used before initialization. You need to swap these lines:

var data = {
    name: 'Jane Doe'
}

$('.updates').append( template(data) );

jsfiddle.net/xnrzwa59/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question