Re: [請益] 關於Smarty的樣板用法
感謝b大 精闢的解答
我想這也大概是我想採用的模式
此外我還想問問 各位有使用類似做法的人
如果我的head.tpl 有自己的js css等等
footer.tpl 與tool_1.tpl 也都有獨立的js
請問 tool_1.tpl
是否該寫成 :
[寫法一]
<html>
<head>
<script type="text/javascript" src="tool_1.js"></script>
</hread>
<body>
<p> tool body</p>
</body>
</html>
還是寫成 :
[寫法二]
<script type="text/javascript" src="tool_1.js"></script>
<p> tool body</p>
或者 乾脆都不加js:
[寫法三]
<p> tool body</p>
而js的部分 就寫在主頁的樣板中?
希望大家能給點解答了,謝謝
※ 引述《bobju (寶貝豬)》之銘言:
: 方法一跟方法二應該都可以用, 甚至可以混用. 至於要採用哪種方式則
: 應該從系統架構規劃的角度來看. 底下提供一個設計樣式僅供參考:
: 資料層 控制層 表達層
: +---[response]----+
: | v assign
: DB_Obj<---[SQL]-----list.php--[display/smarty]-->main.tpl
: |
: +---[response]----+ +head.tpl
: | v +footer.tpl
: DB_Obj1<---[SQL]----tool_1.php---[response]----->+tool_1.tpl
: ^ |
: +------[request/ajax]--------+
: ※ 引述《sqaure (sqaure)》之銘言:
: : 我想做的是 :
: : [list.php]
: : $smarty = new $smarty();
: : //....相關設定後
: : $smarty->assign("content" , "list.tpl");
: : //query articles....
: : $smarty->assign("article" , articles);
: : $smarty->display("main.tpl");
: : [main.tpl]
: : {include file="head.tpl"}
: : -------┬-------------------------
: : tool |
: : div1 | {include file = $content}
: : ------┤
: : tool |
: : div2 |
: : : |
: : -------┴--------------------------
: : {include file="footer.tpl"}
: : main.tpl 是一個共用的樣板
: : 主要架構就是 頁面的header跟footer都是固定的靜態樣板(方便未來可替換用)
: : 直接利用smarty { include file="header.tpl"} { include file="footer.tpl"}
: : 就可以解決,
: : 而畫面中主要的內容區 主要是利用assign $content 來選擇想顯示的樣板(例如
: : $content= list.tpl (文章列表) )
: : 同時把$content的樣板中的資料 assign 進去
: : 最後在整個 $smarty->display("main.tpl") 就會顯示出所有畫面
: : 這是的初步構想 也的確是work的
: : 但比較大的問題就是 左方的功能列 是類似一個個的小視窗
: : 每個小視窗都希望 未來是可以獨立運作的
: : 例如 : tool_1.php <---> tool_1.tpl
: : 請問這樣該怎麼做呢?
: : 做法一 : 如同$content
: : {include file="tool_1.tpl"}
: : 同時在list.php 當中 assign tool_1.tpl中所需要的資料
: : 缺點 : 如果tool_1.tpl 又需要 給其他頁面共用
: : assign 給 tool_1.tpl的資料 又要再重複寫一次
: : 作法二 : 利用ajax 的方式 送出request 要求tool_1.php
: : 將responseText貼回 小視窗的div中
: : 缺點 : 寫法較為困難,後續維護需要更高技巧
: : 其tool_1的相關js 與css,又要另外請求利用javascript 加入link到
: : list.tpl的DOM中
: : 目前我是採取 做法二 ,但不知道是否各位有更好的做法?
: : 因為目前所開發的網站中 會有很多如此共用的頁面
: : 所以才想要避免程式碼重複寫,以便維護
: : 希望能聽聽大家的意見。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.162.209
推
03/03 00:04, , 1F
03/03 00:04, 1F
→
03/03 00:05, , 2F
03/03 00:05, 2F
→
03/03 00:07, , 3F
03/03 00:07, 3F
→
03/03 00:08, , 4F
03/03 00:08, 4F
→
03/03 00:08, , 5F
03/03 00:08, 5F
→
03/03 00:09, , 6F
03/03 00:09, 6F
→
03/03 00:10, , 7F
03/03 00:10, 7F
→
03/03 00:11, , 8F
03/03 00:11, 8F
→
03/03 00:11, , 9F
03/03 00:11, 9F
→
03/03 00:12, , 10F
03/03 00:12, 10F
推
03/05 23:06, , 11F
03/05 23:06, 11F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 6 之 6 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章