Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8884

cant see model from template

I am unable to set model to template, I am trying to do like this: from my view:

 var tmpl = _.template($('#table_template').html() );
        view.$el.html(tmpl(listSongs));

and my template:

   </div><!-- /.row -->
    <div class="list-group">
        <div  id="table_template">
            <%= listSongs.nextLink %>
        </div>
        <nav>
            <ul class="pager">
                <li><a href="#">Previous</a></li>
                <li><a href="#">Next</a></li>
            </ul>
        </nav>

but the issue that when I see just <%= listSongs.nextLink %>

Upvotes: 0

Views: 46

Answers (1)

Spike
Spike

Reputation: 741

You put the template inside your HTML, so its contents are treated as a part of the page and the text is shown.

The solution is to put the template inside a <script> tag of a custom type:

<script id="table_template" type="text/template">
    <div>
        <%= listSongs.nextLink %>
    </div>
</script>

This way, the browser ignores the template and does not treat it as a part of the page.

This is based on an example from Backbone, The Primer.

Upvotes: 1

Related Questions