:::
7-1 讓前後台統一主樣板
- 將原本的
admin.tpl的主要結構另存為templates/op_create.tpl<h3>管理界面</h3> <div class="row"> <div class="col-md-9"> <!-- 編輯表單 --> {include file="admin_create.tpl"} </div> <div class="col-md-3"> <!-- 側邊欄 --> {include file="index_side.tpl"} </div> </div> - 最後
admin.tpl看起來像這樣,和index.tpl幾乎一模一樣,只差web_title不同而已:<!doctype html> <html lang="en"> {include file="index_head.tpl" web_title="校園日誌管理"} <body> <header> <!-- 導覽列 --> {include file="index_nav.tpl"} </header> <main> <div class="container"> {include file="op_{$op}.tpl"} </div> </main> <footer> <!-- Bootstrap JavaScript Libraries --> <script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script> Fancybox.bind("[data-fancybox]"); </script> </footer> </body> </html> - 我們可以讓
admin.php改套用index.tpl,只要多設一個$web_title變數,並送至樣板即可。<?php require_once 'header.php'; // 變數過濾 $op = isset($_REQUEST['op']) ? htmlspecialchars($_REQUEST['op']) : 'create'; switch ($op) { case 'store': $id = store(); //執行後轉向 header("location: index.php?op=show&id=$id"); exit; default: $op = 'create'; break; } $smarty->assign('op', $op); $smarty->assign('categories', $categories); $smarty->assign('year_count', year_count()); $smarty->assign('web_title', '校園日誌管理界面'); $smarty->display('index.tpl'); index.php也一樣多設一個$web_title變數,並送至樣板即可。$smarty->assign('op', $op); $smarty->assign('categories', $categories); $smarty->assign('year_count', year_count()); $smarty->assign('web_title', '校園日誌'); $smarty->display('index.tpl');index.tpl本身則不再需要設定$web_title變數,admin.tpl也可以刪除了。<!doctype html> <html lang="en"> {include file="index_head.tpl"} <body> <header> <!-- 導覽列 --> {include file="index_nav.tpl"} </header> <main> <div class="container"> {include file="op_{$op}.tpl"} </div> </main> <footer> <!-- Bootstrap JavaScript Libraries --> <script src="/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script> Fancybox.bind("[data-fancybox]"); </script> </footer> </body> </html>- 這樣前後台就可以都用同一個樣板囉!可以試試是否能正常發布文章~
7. 後台發布文章界面