How do I pass parameters from template to class-methods

silverstripe-4
templates
Tags: #<Tag:0x00007f10cfd9da28> #<Tag:0x00007f10cfd9d730>

#1

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();
}

#2

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());
}

#3

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)


#4

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.