0

I want to remain DRY with my templates so I created some amazing composable functions and helpers only to realize that Spacebars doesn't play nicely.

I have 2 functions that both take two arguments: func(a,b) which in Spacebars turns into {{func a b}}.

The goal is to compute func2(func1(a,b), c). I figured Spacebars would look at the functions and number of arguments for each be be able to understand {{func2 func1 a b c}}. This doesn't seem to be the case. Any ideas?

Keith Dawson
  • 1,475
  • 16
  • 27
Chet
  • 18,421
  • 15
  • 69
  • 113

1 Answers1

1

There's no such thing as number of arguments in Javascript. You can define function with no explicit arguments:

var f = function() {
  return arguments[0] + arguments[1] + arguments[2];
};

And then call it with how many arguments you like:

f(1,2,3,4,5,6,7,8);

Since Spacebars are ultimately translated to Javascript, they inherit this behavior.

There's no simple way to achieve what you want right now, sadly. You'd need more functions. Probably the easiest solution would be to define func2reverse and call it with reversed order of arguments: {{func2reverse c func1 a b}}

Hubert OG
  • 19,314
  • 7
  • 45
  • 73