我建立了一些基本的Mustache templates 对于一个项目,现在我想有效地将它们作为小部件提供给WordPress。
//This uses Composer to manage dependencies (Mustache).
require \'vendor/autoload.php\';
$mustaches = array_diff(scandir(dirname(__FILE__) . \'/templates\'), array(\'..\', \'.\'));
$templates = array();
foreach ($mustaches as $mustache) {
$code = file_get_contents(dirname(__FILE__) . \'/templates/\' . $mustache);
$templates[$mustache] = array(
\'id\' => str_replace(\'.mustache\', \'\', $mustache),
\'template\' => $code,
\'name\' => preg_replace(\'/\\{\\{\\! name\\: \\"(.*?)\\"\\}\\}/\', \'$1\' , explode("\\n", $code, 1)), //Human name defined in comment at start of template.
);
}
现在我该怎么办?我不能这样动态定义类:
foreach ($mustaches as $mustache) {
class $mustache extends WP_Widget { ...
这会产生语法错误,因为动态扩展并不是任何人都会做的事情。
How do I register multiple widgets with a single class definition?
非常感谢。