Reputation: 11
Inserting a variable argument into a Silverstripe template's function?
I am trying to pass a variable to a template control function. Is the above answer still current for SS3? Or is there a better way of doing it now?
Thanks, Rob
Upvotes: 1
Views: 2666
Reputation: 6094
passing dynamic values to function calls in templates is possible in silverstripe 3. try the following:
Page class:
public function testfunc($myval) {
return 'value is '.$myval;
}
public function testval() {
return 'foobar';
}
Page template:
$testfunc($testval)
this will output 'foobar' in your template as expected.
note that the control
directive is deprecated in ss3, use loop
or with
instead (see http://doc.silverstripe.org/framework/en/reference/templates)
Upvotes: 2