Skip to content

what are handlebars' lambdas and how to use them? #2066

Answered by jaylinski
iamstarkov asked this question in Q&A
Discussion options

You must be logged in to vote

Mustache-style lambdas

// Pseudo code
const template = compile("{{today}}");
template({
  year: 1970,
  today: function() {
    return "Year: {{year}}"
  }
});

Source: https://mustache.github.io/mustache.5.html

Handlebars lambdas

const template = compile("{{today}}");
template({
  year: () => 1970,
  today: function () {
    return `Year: ${this.year()}`;
  }
});

Source:

it('lambdas resolved by blockHelperMissing are bound to the context', function () {
expectTemplate('{{#truthy}}yep{{/truthy}}')
.withInput({
truthy: function () {
return this.truthiness();
},
truthiness: function () {
r…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by iamstarkov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2065 on March 20, 2025 19:53.