0

Based on How do I accomplish an if/else in mustache.js? and calling function with arguments in mustache javascript, I know I can create conditionals in mustache.js templates and also invoke functions to print something on my rendered HTML.

But can they both be combined ? That is, can we "if" the result of a function ?

In pseudo-code:

If someFunction(args){ 
    // print something
}

With mustache.js notation:

{{#someFunction}}someValue{{/someFunction}}

This would output the result of the evaluation of someFunction. Can we print only if the function's evaluation is positive ?

I know about the "logic-less templating", but a developer's gotta do what a developer's gotta do.

Community
  • 1
  • 1
jovin4
  • 35
  • 1
  • 6

1 Answers1

0

You need your function to return a value, and then evaluate that value within your if-statement. This is the general logic as below...

function returnBool(b){
   return b;
}

if (returnBool(true) === true){
  mustache.render();
}
IronAces
  • 1,857
  • 1
  • 27
  • 36