How do I pass parameters from template to class-methods

4.3

How do I pass parameters from template to class-methods

I want to pass 2 Params from template to a method of my class.
The Method is working without parameters. If it requests parameters and I
send them from the template. I get an error: Too few arguments to function
So it seems that the parameter are not transfered…

Template:

<% loop $FunctionWithParams(100,200) %>
<% end_loop %>

PHP

public function FunctionWithParams($a,$b){
return $this->Children();
}

It looks like it should work to me. Maybe try leaving your template how it is but change your method like so to debug it:

public function FunctionWithParams(){
    var_dump(func_get_args());
}

ok it works.
poblem was, that my original function name is getFunctionWithParams($a,$b).
If I do not transfer params I can call it in template with FunctionWidthParams()(no get in front). But if I use
parameters the function hast to be called by the full name. ->getFunctionWidthParams($a,$b)

Huh. That sounds like a bug to me, but then again the ‘getters and setters’ documentation is a bit vague. I’ve opened an issue here.

1 Like