【发布时间】:2013-04-11 23:53:49
【问题描述】:
Inserting a variable argument into a Silverstripe template's function?
我正在尝试将变量传递给模板控制函数。 上述答案是否仍然适用于 SS3?或者现在有更好的方法吗?
谢谢, 抢
【问题讨论】:
Inserting a variable argument into a Silverstripe template's function?
我正在尝试将变量传递给模板控制函数。 上述答案是否仍然适用于 SS3?或者现在有更好的方法吗?
谢谢, 抢
【问题讨论】:
在 silverstripe 3 中可以将动态值传递给模板中的函数调用。 尝试以下方法:
页面类:
public function testfunc($myval) {
return 'value is '.$myval;
}
public function testval() {
return 'foobar';
}
页面模板:
$testfunc($testval)
这将按预期在您的模板中输出“foobar”。
请注意 control 指令在 ss3 中已弃用,请改用 loop 或 with(请参阅 http://doc.silverstripe.org/framework/en/reference/templates)
【讨论】: