簡體   English   中英

如何在Moustache中更新模板加載器路徑?

[英]How to update the template loader path in Mustache?

我試圖定義一個替代/默認模板加載器路徑,以防第一個找不到。

目前我用這種方式初始化胡子:

$m = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader($templates_path,array('extension'=>'.php'))
));

然后我渲染模板:

$m->render($my_template_path, $fields);

在同一個Mustache實例下多次調用render方法。 這工作正常,但我不知道如何在不創建新的Mustache實例的情況下更新加載器路徑。

我一直在閱讀文檔 ,但沒有得到它的工作。 我嘗試使用$ loader-> load()而不是render。 這允許我改變路徑,但它不會渲染變量。

所以...我完全錯過了CascadingLoader選項,它允許我設置多個加載器。 我通過將代碼更新為:來獲得了加載的后備路徑:

$m = new Mustache_Engine(array(
    'loader'=> new Mustache_Loader_CascadingLoader(array(
               new Mustache_Loader_FilesystemLoader($templates_path,array('extension'=>'.php')),
               new Mustache_Loader_FilesystemLoader($alt_path,array('extension'=>'.php'))
    ))
));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM