Skip to content

Instantly share code, notes, and snippets.

@fat
Forked from sayrer/gist:1504888
Created January 7, 2012 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fat/1575714 to your computer and use it in GitHub Desktop.
Save fat/1575714 to your computer and use it in GitHub Desktop.
Rendering
// require hogan
var hogan = require("hogan.js");
// 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 });
});
// outputs "Follow: @dhg @fat @jimio @nickgreen @sayrer!"
console.log('Follow: ' + team.join(' ') + '!');
@mytharcher
Copy link

You cannot use team.map() without an assignment to a new variable, because after this team self never changes. Then the team.join() will not be expected.

@dennislaupman
Copy link

Try this one:

// require hogan
var hogan = require("hogan.js");

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

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

var mappedTeam = team.map(function (twitterer) {

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

});

// outputs "Follow: @dhg @fat @jimio @NickGreen @sayrer!"
console.log('Follow: ' + mappedTeam.join(' ') + '!');

@palanik
Copy link

palanik commented Dec 29, 2014

// require hogan
var hogan = require("hogan.js");

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

var team = ['dhg', 'fat', 'jimio', 'nickgreen', 'sayrer']
           .map(function (twitterer) {

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

           });

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment