Silverstripe 3列出特定文件夹中的所有模板(.ss - 文件)

问题描述 投票:1回答:1

是否在Silverstripe 3中有一个现成的功能,让所有模板都存在于一个特定的文件夹中,以便将它们放在Arraylist中?

如果没有,之前有人这样做过吗?

我的目标是从下拉列表或单选按钮集中选择模板。

或者我应该用...

$files = glob("/path/to/directory/*.ss");

谢谢。 SEPP。

php templates arraylist directory silverstripe
1个回答
1
投票

userforms模块does this显示可能的收件人电子邮件模板列表。这是相关部分:

$templates = [];
$finder = new SS_FileFinder();
$finder->setOption('name_regex', '/^.*\.ss$/');
$found = $finder->find(BASE_PATH . '/path/to/directory');
foreach ($found as $key => $value) {
    $template = pathinfo($value);
    $templates[$template['filename']] = $template['filename'];
}
© www.soinside.com 2019 - 2024. All rights reserved.