【问题标题】:RE: Inserting a variable argument into a Silverstripe template's function?RE: 将变量参数插入到 Silverstripe 模板的函数中?
【发布时间】:2013-04-11 23:53:49
【问题描述】:

Inserting a variable argument into a Silverstripe template's function?

我正在尝试将变量传递给模板控制函数。 上述答案是否仍然适用于 SS3?或者现在有更好的方法吗?

谢谢, 抢

【问题讨论】:

    标签: templates silverstripe


    【解决方案1】:

    在 silverstripe 3 中可以将动态值传递给模板中的函数调用。 尝试以下方法:

    页面类:

    public function testfunc($myval) {
        return 'value is '.$myval;
    }
    
    public function testval() {
        return 'foobar';
    }
    

    页面模板:

    $testfunc($testval)
    

    这将按预期在您的模板中输出“foobar”。

    请注意 control 指令在 ss3 中已弃用,请改用 loopwith(请参阅 http://doc.silverstripe.org/framework/en/reference/templates

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-24
      • 2013-03-28
      • 2015-05-02
      • 1970-01-01
      • 2012-08-14
      相关资源
      最近更新 更多