2015-06-27 97 views
0

嘗試使用mustache.php調用鬍子偏好。 我敢肯定我正在搞點東西,因爲文檔似乎表達了你可以做我想做的事情。嘗試在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模板。不知道這是否重要。

回答

0

tl; dr:您可能想要使用echo $m->render('03-ups/00-two-up')

小鬍子使用「加載器」來決定要求提供哪種模板。具體來說,它使用兩個加載器:一個常規的加載器,用於所有render()調用;以及一個可選的partials加載器,用於渲染partials,就像您可能已經猜到的那樣。如果您不指定partials加載器,則會回到主要加載器。

默認情況下,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'); 

如果你真的想用一個字符串裝載機主裝載機,但仍指定了諧音的文件系統加載器,你可以明確地添加它:

new Mustache_Engine([ 
    'partials_loader' => new Mustache_Loader_FilesystemLoader(...) 
]); 
+0

我將不得不嘗試一下...... 我想我記得從渲染參數中刪除「>」,它仍然沒有渲染模板。我會盡快回復您,並告訴您是否有效。 由於使用了patternlab,我在這裏的情況有點粘,因爲我有多個部分文件夾,它將部分文件分解成3個左右不同的文件夾。我沒有看到多個部分裝載機的文檔中的任何內容,但也許我沒有看到它? 我很欣賞創造者幫助我,雖然這很酷=) – Ashleigh