2015-01-08 21 views
0

我很抱歉這個愚蠢的問題,但我不明白!小鬍子 - 如何建立一個導航/鏈接

我想建立一個簡單的網站前端像這樣的例子有鬍子: http://detector.dmolsen.com/demo/mustache/

如果我只有一個頁面一個網站 - 一切都很好: 創建我的鬍子對象...和等

// use .html instead of .mustache for default template extension 
 
$options = array('extension' => '.html'); 
 

 
// Template and Partial - Filesystem Loader 
 
$mustache = new Mustache_Engine(array(
 
    'loader' => new Mustache_Loader_FilesystemLoader(__DIR__.'/views', $options), 
 
    'partials_loader' => new Mustache_Loader_FilesystemLoader(__DIR__.'/views/partials/'.$GLOBALS['comparedDeviceInformation']['Device Class'], $options), 
 
));

在這之後我使我的索引模板:

// render index.html template 
 
echo $mustache->render('index', $data);

這工作完全正常! 現在在這個'index.html'模板文件中,我不想鏈接到另一個模板,例如home.html的

<a href="?????">home</a>
如何使這樣一個動態渲染?它不可能是每個頁面模板都有一個php文件的解決方案嗎?

我該如何處理網址?我不能使用模板的名稱?所以我如何得到一個一致的網址結構爲我的網站

非常感謝!

回答

0

小鬍子本身只是一個模板引擎......它不關心你有什麼URL,或者有多少PHP文件,或者除了將模板轉換爲HTML之外的任何東西。對於所有其他的事情,你有幾個選擇。最直接的方法是爲每個你想要處理的URL分配一個PHP文件。正如你所說,這是不理想:)

我會建議檢查一個輕量級的PHP框架。他們處理路由(將URL映射到呈現的頁面)併爲後端提供更多結構。 Here is a list of some of the ones Mustache.php plays nice with。爲了您的目的,Silex或Slim可能會很適合。

+0

非常感謝你:) – Christoph

+0

不是問題:) – bobthecow