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.

1 Answer 1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.