【问题标题】:Silverstripe 4: Include Template from FilepathSilverstripe 4:包含来自文件路径的模板
【发布时间】:2018-06-20 22:41:50
【问题描述】:

我正在开发一个 Silverstripe 4 项目,我们需要从路径中包含一个 SS 模板文件。

这是一个简单的示例,说明了我想要实现的目标。

class ExampleController extends ContentController
{    
  public function IncludeTemplateFromFilePath() {
    var $FilePath = '/path/to/file';
    ???
    return $output
  }
}

模板语法:

<div>$IncludeTemplateFromFilePath</div>

我查看了SSViewer documentation 并查看了 Silverstripe 源代码,但无法找出正确的语法来完成这项工作。

有很多例子:

return SSViewer::get_templates_by_class(static::class, $suffix, self::class);

但是从文件路径获取模板的语法是什么?

【问题讨论】:

    标签: silverstripe silverstripe-4


    【解决方案1】:

    我相信你可以做到以下几点:

    public function IncludeTemplateFromFilePath()
    {
        return SSViewer::execute_string(
            file_get_contents('/path/to/Template.ss'),
            [
                'Content' => 'Value that will be in $Content when used in /path/to/Template.ss'
            ]
        );
    }
    

    参考:http://api.silverstripe.org/4/SilverStripe/View/SSViewer.html#method_execute_string

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      • 2016-04-13
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      相关资源
      最近更新 更多