尝试使用mustache.php调用小胡子部分。我确信我搞砸了什么,因为文档似乎表明您可以做我正在尝试做的事情。
$m = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/patternlab-php-master/source/_patterns/02-organisms/'),
));
echo $m->render('{{> 03-ups/00-two-up }}');我得到了这个错误:
Fatal error: Uncaught exception 'Mustache_Exception_UnknownTemplateException' with message 'Unknown template: {{> 03-ups/00-two-up }}' in C:\xampp\htdocs\grogan\wordpress\wp-content\themes\grogan-theme\vendor\mustache\mustache\src\Mustache\Loader\FilesystemLoader.php:102
Stack trace:
#0 C:\xampp\htdocs\grogan\wordpress\wp-content\themes\grogan-theme\vendor\mustache\mustache\src\Mustache\Loader\FilesystemLoader.php(82): Mustache_Loader_FilesystemLoader->loadFile('{{> 03-ups/00-t...')
#1 C:\xampp\htdocs\grogan\wordpress\wp-content\themes\grogan-theme\vendor\mustache\mustache\src\Mustache\Engine.php(617): Mustache_Loader_FilesystemLoader->load('{{> 03-ups/00-t...')
#2 C:\xampp\htdocs\grogan\wordpress\wp-content\themes\grogan-theme\vendor\mustache\mustache\src\Mustache\Engine.php(217): Mustache_Engine->loadTemplate('{{> 03-ups/00-t...')
#3 C:\xampp\htdocs\grogan\wordpress\wp-content\themes\grogan-theme\page-consignment.php(46): Mustache_Engine->render('{{> 03-ups/00-t...')
#4 C:\xampp\htdocs\grogan\wordpress\wp-includes\templ in C:\xampp\htdocs\grogan\wordpress\wp-content\themes\grogan-theme\vendor\mustache\mustache\src\Mustache\Loader\FilesystemLoader.php on line 102我正在使用patternlab来存放我的所有部分,并将它们调用到wordpress模板中。不确定这是否重要。
发布于 2015-06-30 00:30:31
tl;dr:您可能想要使用echo $m->render('03-ups/00-two-up')。
Mustache使用“加载器”来决定当你请求一个模板时要呈现什么模板。具体地说,它使用两个加载器:一个是常规加载器,用于所有render()调用;另一个是可选的部分加载器,用于呈现部分加载器,正如您可能已经猜到的那样。如果你没有指定一个部分参数加载器,它会返回到主加载器。
默认情况下,Mustache使用字符串加载器作为主加载器。这就是为什么您可以开箱即用地调用$m->render('string with {{mustaches}}')。但是字符串加载器并不适用于超过一行的模板,因此通常需要指定文件系统加载器。这将获取一个基本目录,并根据名称从文件中加载模板。因此,如果调用$m->render('foo'),它将在文件系统加载器的基目录中查找名为foo.mustache的文件。
这就是您配置它要做的事情,在异常消息中有一个提示:它显示为Unknown template: {{> 03-ups/00-two-up }},意思是“我试图找到一个名为{{> 03-ups/00-two-up }}.mustache的文件,但没有一个”:)
如果您将调用更改为实际的模板名称,它将起作用:
echo $m->render('03-ups/00-two-up');如果您确实希望将字符串加载器用于主加载器,但仍指定了partials文件系统加载器,则可以显式添加它:
new Mustache_Engine([
'partials_loader' => new Mustache_Loader_FilesystemLoader(...)
]);https://stackoverflow.com/questions/31093118
复制相似问题