I am very new to backbone.js ,I am practicing to display templates in my 'index.html' page. I have created a template in In 'index.html' and displaying it in a using view.It works fine with single html file i.e. everything is kept in 'index.html'.But now i want those templates to store in other file and display in my 'index.html'. I tried to find some solution ,but all were confusing. SO please, can anyone tell me how should i do it.
Following is my template to be display(currently in a 'index.html'):
<script type="text/template" id="cloudtag_tempalte">
<center>
<ul class="cld" ">
<li > <a class="tag1" id="t1" href="https://www.google.com" target="_blank"></a> </li>
<li > <a class="tag2" id="t2" href="#">sachin </a> </li>
<li > <a class="tag3" id="t3" href="#">Ramesh </a> </li>
<li > <a class="tag1"id="t33" href="#">Tendulkar</a></li>
<li > <a class="tag5"id="t34" href="#">Cricket</a></li>
<li > <a class="tag2"id="t35" href="#">Test</a></li>
</ul><!--/cld-->
</center>
</script>
Following is a div in which it is displayed(in same 'index.html'):
<div class="tags" id="myTags"> </div><!--/tags-->
and following is script of view(in same file 'index.html'):
<script type="text/javascript">
var cld_view=Backbone.View.extend({
initialize: function(){
},
render: function(){
// Compile the template using underscore
var template = _.template( $("#cloudtag_tempalte").html(), {} );
// Load the compiled HTML into the Backbone "el"
this.$el.html( template );
}
});
var cloudtag=new cld_view({el:$("#myTags")});
cloudtag.render();
</script>
So please, suggest me changes to be made to make this template external . Thanx in advence . . .