:::

14. 樣板及評論

一、讓您的模組更容易設計外觀

1.我們來讓view.php這一頁,套用樣版。為什麼要套用樣板?套用樣板好處如下:
(1) 可以使用評論或通知功能
(2) 使用者可以很方便的修改程式頁面(視您的樣板精細程度)

二、模組套用樣板步驟

1.模組不一定要套用樣板,但若有用到樣板時,一定要到xoops_version.php做以下設定。設定也是兩個一組,陣列從1開始。
(1) $modversion['templates'][1]['file'] = 'view_tpl.html';
安裝或更新模組時,會根據此設定讀入該樣板內容到資料庫。
(2) $modversion['templates'][1]['description'] = "佈景說明";
樣板描述,從後台的樣板管理就會看得到。(常數不用加引號,不然系統讀不到)
2.建立templates/view_tpl.html,該檔內容一行即可,樣板碼可自訂:
<{$樣板碼}> 例如:<{$content}>
3.到後台更新您的模組,讓XOOPS重讀xoops_version.php設定檔。
4.在view.php中加入「$xoopsOption['template_main'] = "view_tpl.html";」
5.用「$xoopsTpl->assign( "content" , $main) ;」來把內容套入樣板,其中 content就是樣板標籤<{$content}>,而$main就是要套用進去的內容。

三、評論功能(Comments)

1.若是想要在模組中套用評論功能,那麼必須設定以下項目:
(1) $modversion['hasComments'] = 1;
是否啟用評論功能?
(2) $modversion['comments']['itemName'] = 'sn';
評論項目的唯一辨識欄位的名稱(給程式用的)
(3) $modversion['comments']['pageName'] = 'view.php';
要加入評論的頁面
2.接著把「評論檔」中的五個檔案複製到「模組根目錄」。
3.在view.php的下方include....foot.php前加入一行:


include_once XOOPS_ROOT_PATH.'/include/comment_view.php';
include_once XOOPS_ROOT_PATH.'/footer.php';
?>

4.開啟教材中的「評論樣板檔語法.txt」,複製裡面的語法到樣版檔view_tpl.html 中

<{$content}>

<div style="margin: 3px; padding: 3px;">
<!-- start comments loop -->
<{if $comment_mode == "flat"}>
  <{include file="db:system_comments_flat.html"}>
<{elseif $comment_mode == "thread"}>
  <{include file="db:system_comments_thread.html"}>
<{elseif $comment_mode == "nest"}>
  <{include file="db:system_comments_nest.html"}>
<{/if}>
<!-- end comments loop →
</div>


5.到後台更新您的模組(為了重讀樣版及設定檔),就大功告成囉!


:::

搜尋

QR Code 區塊

https%3A%2F%2Fwww.tad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D5%26tbdsn%3D112

書籍目錄

展開 | 闔起

線上使用者

40人線上 (8人在瀏覽線上書籍)

會員: 0

訪客: 40

更多…