boeiBlog 採用 PHPLib 7.4 模板引擎(class/template.class.php),優勢在於模板頁面簡單、邏輯與呈現分離,適合個人部落格系統。
| 方法 | 用途 |
|---|---|
set_file() | 載入模板檔案,建立 handle |
set_block() | 宣告區塊,支援巢狀 |
set_var() | 設定變數值 |
parse() | 解析模板,結果存入 target handle |
pparse() | 解析並直接輸出 |
p() / get() | 輸出/取回已解析變數 |
{var_name}(大括號包裹)。<!-- BEGIN block_name -->
... 區塊內容 ...
<!-- END block_name -->
<table>
<!-- BEGIN rowlist -->
<tr>
<!-- BEGIN collist -->
<td>{cell_value}</td>
<!-- END collist -->
</tr>
<!-- END rowlist -->
</table>
<?php
$t = new Template("templates/");
$t->set_file("show_main", "main.htm");
$t->set_file(array(
"show_header" => "header.htm",
"show_footer" => "footer.htm"
));
// 宣告區塊
$t->set_block("show_main", "rowlist", "RL");
$t->set_block("RL", "collist", "CL");
// 迴圈資料
foreach ($articles as $art) {
$t->set_var("title", $art['title']);
$t->set_var("date", $art['date']);
$t->parse("RL", "rowlist", true); // 累加行
foreach ($art['tags'] as $tag) {
$t->set_var("tag_name", $tag);
$t->parse("CL", "collist", true);
}
}
$t->pparse("show_header");
$t->pparse("show_main");
$t->pparse("show_footer");
?>
[[ ]] 代替,發布前替換。