-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
defining complex helper functions in mustache.js #480
Comments
Sorry, this is intentionally not possible in mustache, as function calls and parameters are fundamentally incompatible with mustache's "logic-free" core principle. You should be preparing your data model before sending it to the template. If this is really something you need, handlebars might be a better fit. |
I see - I thought it might be intentional. Mustache.js does support helper functions though: https://github.com/janl/mustache.js#functions I thought that limiting those functions to not take any parameters seems like kind of an arbitrary limitation. If the aim is for Mustache to be "logic-free", wouldn't you remove helper functions? |
Those are lambda sections, and they're an optional part of the mustache spec. I'm personally of the opinion that they're not necessary, but they do exist, and most mustache implementations support them. And yes, people abuse them to add logic to their templates. |
I see.. thanks for the explanation. |
kindly re-open this,
lambdas are important part of the spec those who wrote the spec knows the principles of mustache better
to help templates be logic-free, template designers has two options not only mustach but also Django is also logic-free, but they also have filters for example in jinja
in original mustache spec
the point of all this is not to say that jinja or golang is better than mustach, and I know mustach is more strict than others about logic, |
This issue isn’t about filters or lambdas. I agree with you about both of those. But this issue is about calling functions from inside mustache templates which take parameters. |
surely you can call functions from within templates using the |
The more intutive in logic-free templates is
|
Is it possible to define a helper function that takes multiple arguments in Mustache.js 2.1.3, like this Handlebars function?
(https://github.com/assemble/handlebars-helpers/blob/master/lib/helpers/helpers-strings.js#L237)
If not, would this be complicated to implement? I need this feature for one of my projects.
The text was updated successfully, but these errors were encountered: