title: Uncaught TypeError: Cannot call method 'replace' of undefined underscore.js
body: <p>I'm newbie to <code>backbone.js</code> and <code>underscore.js</code>.</p>
  
  <p>HTML :</p>
  
  <pre><code>&lt;div id="cartlist"&gt;
  &lt;script type="text/template" id="cart_template"&gt;
  
  &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Where I called the view file : </p>
  
  <pre><code>&lt;script type="text/javascript" src="webcore/views/CartView.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>JS function(it works well with the javascript project):</p>
  
  <pre><code> function Cart(){
      ......
      this.showCart = function (){
      var item = deserializeJSONToObj(window.localStorage.getItem(Cart.storageName));
      var str = '&lt;table id="showcart"&gt;';
      str += '&lt;tr&gt;&lt;td class="cartitemhead"&gt;Item to buy&lt;/td&gt;&lt;td class="cartitemhead" style="text-align: center;"&gt;Quantity&lt;/td&gt;&lt;/tr&gt;';
      $.each(item, function(i, item) {
          str += '&lt;tr&gt;&lt;td&gt;&lt;table class="verticallist"&gt;&lt;tr&gt;&lt;td rowspan="4" style="width: 120px;"&gt;&lt;img src="' + item.PictureName + '" alt="Product" width="95px"/&gt;&lt;/td&gt;&lt;td style="font-weight: bold;"&gt;'+trimString(item.Name,50)+'&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;i&gt;Available in Stock(s)!&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;i&gt;Rating:   650Va-390w Input:   Single&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;td class="centertxt"&gt;'+item.QuantityInCart+'&lt;/td&gt;&lt;/tr&gt;';
      });
      str += '&lt;/table&gt;';
      return str;
   } 
  </code></pre>
  
  <p>This is the Views :</p>
  
  <pre><code>var myCart = new Cart();
  CartList = Backbone.View.extend({
  initialize:function(){
      this.render();
  },
  render: function(){
      var template = _.template( $("#cart_template").html(), {} );
      this.$el.html( template );
  }
  });
  var cart_view = new CartList({ el: $("#cartlist").html(myCart.showCart()) });
  </code></pre>
  
  <ol>
  <li><p>when I trying to call the view template, I am getting error <code>Uncaught TypeError: Cannot call method 'replace' of undefined - underscore.js</code>. Please help me to find the mistake.</p></li>
  <li><p>How can I convert <code>str</code> string in <code>Cart</code> class to a <code>template</code> of <code>underscore.js</code>. </p></li>
  </ol>
  
  <p>Any help would be much appreciated, thank you.</p>