Silverstripe 4:包含来自文件路径的模板
我正在进行一个Silverstripe 4项目,其中需要包含一个来自路径的SS模板文件 下面是一个简单的例子,给出了我想要实现的要点Silverstripe 4:包含来自文件路径的模板,silverstripe,silverstripe-4,Silverstripe,Silverstripe 4,我正在进行一个Silverstripe 4项目,其中需要包含一个来自路径的SS模板文件 下面是一个简单的例子,给出了我想要实现的要点 class ExampleController extends ContentController { public function IncludeTemplateFromFilePath() { var $FilePath = '/path/to/file'; ??? return $output } } 模板语法:
class ExampleController extends ContentController
{
public function IncludeTemplateFromFilePath() {
var $FilePath = '/path/to/file';
???
return $output
}
}
模板语法:
<div>$IncludeTemplateFromFilePath</div>
但是从模板的文件路径获取模板的语法是什么?我相信您可以执行以下操作:
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'
]
);
}
参考:
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'
]
);
}