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

How can a function could be called from json in mustache CLI? #747

Closed
ph1-xyz opened this issue Mar 18, 2020 · 3 comments
Closed

How can a function could be called from json in mustache CLI? #747

ph1-xyz opened this issue Mar 18, 2020 · 3 comments

Comments

@ph1-xyz
Copy link

ph1-xyz commented Mar 18, 2020

Hi!
I'm trying to execute from mustacheCLI a function residing in the dataView.json. This brings me an error, saying that JSON cannot contain functions...

How can one use mustache's functionality to execute functions from CLI?

Thanks

@phillipj
Copy link
Collaborator

Hi there!

The error you're describing is a JSON limitation; functions cannot be serialised into JSON.

So in #717 we allowed our CLI to be given a .js file as the view, instead of a .json file. If we use the test files (./test/_files/cli_js_view_with_function.js & ./test/_files/cli_js_view_with_function.mustache) we got in this repo as an example, you could use the CLI to render the output:

$ mustache cli_js_view_with_function.js cli_js_view_with_function.mustache

Does that make sense?

@ph1-xyz
Copy link
Author

ph1-xyz commented Mar 18, 2020

Thank you very much, I'm going to try immediately.

I also commented here explaining a bit what I was trying to do, hope what you just pointed out solves it!

Edit: It surely works. At the moment it behaves weirdly in my code, but it must be me. Anyways, this is a great improvement for the library, it could be worth to be mentioned in the Read me!

@phillipj
Copy link
Collaborator

Thanks for confirming it works as intended!

Good suggestion mentioning the fact that .js could also be used in addition to .json, feel free to open a PR with an improvement 😄

Closing this for now as your question has been answered.

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

2 participants