Drupal6.0 theming 模版初探

上一次的更新已經是....九月!?!?
吐血中, 讀者們...不要走.....^^
留言的....多謝你們~無言以報

入正題
從freelance 的血海之中抽身,
花了些許時間研究Drupal6.x 的theming system (模版系統)
一句說話, 驚為天人

前言
http://drupal.org/node/171188
講得很清楚, Drupal6.x 和5.x 一樣,
所有個人化, 修改代碼的工作都應該發生在 /sites 資料夾之內
這次的目標是在 /user/* 的頁面,
用戶名之後加代碼 (這次是簡單的加一個"a")

準備
Druapl6.x 的theming 修改都是屬於某一theme 的
即是說, 修改garland 之後, 用戶轉到其他theme 便看不到修改了
(當然, 有其他方法"強行"用到全部theme...)
先將 /themes/garland 抄到 /sites/themes/garland (需要自建資料夾)
雖然Drupal6.x 不會再用theme 資料夾名決定theme 名稱,
但為了分別, 還是改: /sites/themes/garland -> /sites/themes/garland2
真正的修改theme 的名稱, 就要修改garland.info -> garland2.info
theme 資料夾內的 *.info 決定theme 的名稱
當然, 順手改一下 garland2.info 內的 name 參數
先不要到administer 改theme 成garland2

另外, theme 的開發者在6.x 之後得到一個極強力的幫手,
devel module
內裏的theme developer 便是"drupal 內的 firebug"
下載devel, 解壓到 /sites/modules/devel (需要自建資料夾)
到URL: /admin/build/modules 啟用模組
你就會看到

代表安裝成功了

正題
到目標URL: /user/1
點擊theme developer 以啟用
然後你只要指到你想要修改的element 之上, theme developer 就會告訴你要修改那裏:

/modules/user/user-profile.tpl.php (你指的可能是 user_profile_category.tpl.php 但這 tpl 是包在user-profile.tpl.php 之內的)
將/modules/user/user-profile.tpl.php 抄到 /sites/themes/garland2/user-profile.tpl.php
打開 /sites/themes/garland2/user-profile.tpl.php, 改成:

<div class="profile">
a
  <?php print $user_profile; ?>
</div>

儲存, 完成.
到URL: /admin/build/themes 改用garland2 作為預設theme

結語
有了devel module, 開發快了很多很多, 免除了追蹤xhtml 來自那裏個檔案的麻煩
修改的門檻低了很多, 只要安裝了devel module, 一般人只要些少訓練就可以改theme 了
現時關於Drupal6.x theming 的資料只是剛好足夠明白基本原理
主站的 handbook 還需要很多很多教學, 例子才可以令人看得懂....
最後一點, 有點奇怪的是, theme 只可以在安裝的時候找一次theme 內的 *.tpl.php(修正1)
即是說, 轉到新的theme 之前要決定好theme 內有那些 tpl.php
只是這點比較麻煩

連結
Overriding themable output - 這次的主要參考
http://drupal.org/node/173880

修正

  1. 2008-02-20: 這是因為theme registry
AttachmentSize
94-1.gif17.34 KB
94-2.gif1.42 KB
94-3.gif13.18 KB

Comments

没有走 没有走

没有走 没有走 不会走

^___^ joe终于有更新了,潜心学习中。
dp6我已经开始部署正式站点,但于模板还有需要学习的地方。正好到这里学习了。

一起鑽研吧~

一起鑽研吧~

6.0版本里文章下评论的设置在哪?

就是设置评论的显示,和设置成预览与提交按钮可选的地方在哪?你能告诉我么?谢谢了!
http://drupalchina.org/node/3848

Joe Tsui,thanks for a lot!

近一个月来观察DRUPAL这个CMS的研究价值;
近一个星期以来观摩贵博的文字信息...
我现在要说的是,
Joe Tsui,
即使研究不透这个CMS的价值所在,即使自己无能把这个程序学精,但跟你这样好的人品的人学习,相信也一定能学到有用的东西~!
相信DRUPAL,相信你!

学习了,以后会长来

学习了,以后会长来

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <h4> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options