Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Mustache.render() and Mustache.to_html()?

Tags:

The documentation makes no mention of Mustache.to_html(), but every tutorial for Mustache.js online uses Mustache.to_html(). Therefore I am surely missing some jewels.

Code examples would be very much appreciated.

like image 249
ehabd Avatar asked Jun 03 '12 17:06

ehabd


People also ask

What does mustache render do?

Mustache is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. We call it "logic-less" because there are no if statements, else clauses, or for loops.

What is Mustache in programming?

Mustache is a web template system with implementations available for ActionScript, C++, Clojure, CoffeeScript, ColdFusion, Common Lisp, Crystal, D, Dart, Delphi, Elixir, Erlang, Fantom, Go, Haskell, Io, Java, JavaScript, Julia, Lua, .

How do I render a mustache in HTML?

render = function (template, view, partials) { return this. compile(template)(view, partials); }; This is the most basic form of templating with mustache. Let's see the other methods available for creating more organized code.


1 Answers

Looking at the source, it seems to_html has essentially been deprecated:

// This is here for backwards compatibility with 0.4.x. exports.to_html = function (template, view, partials, send) {     var result = render(template, view, partials);      if (typeof send === "function") {       send(result);     } else {       return result;     } }; 

As you can see it invokes render. The one difference is the extra (optional) send parameter, which is a callback it invokes (sending the result as a parameter).

like image 98
McGarnagle Avatar answered Oct 29 '22 05:10

McGarnagle