Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render is undefined #222

Open
rouberg opened this issue May 20, 2015 · 5 comments
Open

render is undefined #222

rouberg opened this issue May 20, 2015 · 5 comments
Assignees

Comments

@rouberg
Copy link

rouberg commented May 20, 2015

code fragment below is copy from mustache , but I can't get argument render in Lambdas. The console told me argument render is undefined. Is there something that i misunderstand?

Template:

{{#wrapped}}
{{name}} is awesome.
{{/wrapped}}

Hash:

{
"name": "Willy",
"wrapped": function() {
return function(text, render) { //actually param render cannot get a argument
return "" + render(text) + ""
}
}
}

@ex1st
Copy link

ex1st commented May 27, 2015

@rouberg Lambdas in Hogan.js is broken. Please try that.

{
  "wrapped": function() {
    return function(text) {
      return Hogan.compile(text).render(this);
    }
  }
}

@Jerska
Copy link

Jerska commented Jun 18, 2015

See #199

@sayrer
Copy link
Collaborator

sayrer commented Jun 22, 2015

The 'render' argument isn't in the mustache spec.

@Jerska
Copy link

Jerska commented Jun 22, 2015

@sayrer

Lambdas

When the value is a callable object, such as a function or lambda,
the object will be invoked and passed the block of text.
The text passed is the literal block, unrendered. {{tags}} will not
have been expanded - the lambda should do that on its own.
In this way you can implement filters or caching.

Template:

{{#wrapped}}
  {{name}} is awesome.
{{/wrapped}}

Hash:

{
  "name": "Willy",
  "wrapped": function() {
    return function(text, render) {
      return "<b>" + render(text) + "</b>"
    }
  }
}

Output:

<b>Willy is awesome.</b>

You're right, the text only states that the lambda should receive the unrendered chunk of text.
But by looking at the examples, it seems pretty obvious that this is how one could expect hogan.js to behave.
And it would allow to have the same hogan options that Hogan.compile was invoked with instead of having to store them somewhere.

@sayrer
Copy link
Collaborator

sayrer commented May 1, 2021

Six years later, still not sure what the right answer is here, but this should get resolved definitively.

@sayrer sayrer self-assigned this May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants