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

Mustache.js template with function fails using command line tool #429

Closed
hhumml opened this issue Feb 26, 2015 · 6 comments
Closed

Mustache.js template with function fails using command line tool #429

hhumml opened this issue Feb 26, 2015 · 6 comments

Comments

@hhumml
Copy link

hhumml commented Feb 26, 2015

Using the examples from the readme section, I get the following exception when trying it with the command line tool (installed with npm):

undefined:3
    "bold": function () {
             ^
SyntaxError: Unexpected token u
    at Object.parse (native)
    at /usr/local/lib/node_modules/mustache/bin/mustache:49:13
    at ReadStream.<anonymous> (/usr/local/lib/node_modules/mustache/bin/mustache:72:5)
    at ReadStream.g (events.js:180:16)
    at ReadStream.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickCallback (node.js:442:13)

View

{
    "name": "Tater",
    "bold": function () {
        return function (text, render) {
            return "<b>" + render(text) + "</b>";
        }
    }
}

Template

{{#bold}}Hi {{name}}.{{/bold}}

When trying the same within the browser it works. What am I missing?

Background: I want to build a HTML template generator using the command line tool.

@dasilvacontin
Copy link
Collaborator

Hi @hhumml, the view argument is supposed to be a .json file. JSON format doesn't support functions.

@renancarvalhoo
Copy link

@hhumml have example in the documentation of mustache :

Template:

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

Hash:

{
  "name": "Willy",
  "wrapped": function() {
    return function(text, render) {
      return "" + render(text) + ""
    }
  }
}

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

@dasilvacontin
Copy link
Collaborator

@renancarvalhoo, you can't store functions in a .json file.

@renancarvalhoo
Copy link

i know this but you can work the data in the javascript before pass to template mustache.

The documentation speak this.

@dasilvacontin
Copy link
Collaborator

@renancarvalhoo, but @hhumml is talking about using the command line tool.

@echo-layker
Copy link

I have the same problem, how to solve it ?

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