twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

'Rendering' demo on http://twitter.github.io/hogan.js/ doesn't seem to work #227

Closed yochannah closed 3 years ago

yochannah commented 9 years ago

The demo code here http://twitter.github.io/hogan.js/ in the "render" section

  // compile template
  var template = Hogan.compile("@{{name}}");

  var team = ['dhg', 'fat', 'jimio', 'nickgreen', 'sayrer'];

  team.map(function (twitterer) {

  // Render context to template
    return template.render({name: twitterer });
  });

   // SHOULD output "Follow: @dhg @fat @jimio @nickgreen @sayrer!"
   console.log('Follow: ' + team.join(' ') + '!'); 

Expected output, as above:

Follow: @dhg @fat @jimio @nickgreen @sayrer!

But actually it outputs:

"Follow: dhg fat jimio nickgreen sayrer!".

Example: http://jsbin.com/wozafi/edit?html,js,console

I assume either the documentation or the library itself needs any update?

jgraup commented 8 years ago

Try replacing the map function with a simple loop.

  // compile template
  var template = Hogan.compile("@{{name}}");

  var team = ['dhg', 'fat', 'jimio', 'nickgreen', 'sayrer'];

  for (var i in team ){

  // Render context to template
    team[i] = template.render({ name: team[i] });
  }

   // outputs "Follow: @dhg @fat @jimio @nickgreen @sayrer!"
   console.log('Follow: ' + team.join(' ') + '!'); join(' ') + '!'); 
sayrer commented 3 years ago

same as #251.