Search code examples
handlebars.js

First number of result of template is delete


In a view of Brite.js the result of render a handlebars.js template is 1 <span>products</span> but when display the view the number is not show, it only show the span tag and the text.

Template is:

{{num}} <span>products</span>

The view only in create has function that return result of render template.


Solution

  • A brite.js view needs to return (or resolve) to an HTML element, an HTML string (starting with a tag), or a jQuery object pointing to an HTML Element.

    So, something like this should work:

    var counter = 0;
    brite.registerView("MyView",{
    
      create: function(){
         counter++;
         return "<div>" +  + "</div>");
      }
    
    });
    

    Then, every time you call brite.display("MyView","body"), it will add a new div to <body> in this case, with the incremented counter.

    Obviously, the create method can use any templating engine like Handlebars, but the string needs to be an HTML tag.