簡介 *.tpl.php

這是Drupal 使用 *.tpl.php 的基本之中的基本 (無論Drupal5.x, Drupal6.x)
因為很多讀者始終不明白 *.tpl.php 的運作
所有後加這一篇最簡單的篇章
這一篇完成後, 你可以:
story 不顯示作者, 提交時間,
但page 則顯示

我們先完成代碼部份, 再講解其中的原理
將 /themes/garland 資料夾, 複製及更名到 /sites/themes/garland2 (或者你可以使用你喜歡的版型)
到管理->版型 內轉到 garland2 版型為預設
將 garland2 內的 node.tpl.php, 複製成 node-story.tpl.php
打開 node-story.tpl.php, 移除:

  <?php if ($submitted): ?>
    <span class="submitted"><?php print t('!date — !username', array('!username' => theme('username', $node), '!date' => format_date($node->created))); ?></span>
  <?php endif; ?>

儲存, 完成!!!!

簡單吧, 這就是templating 的強大功能了

原理:
Drupal 在顯示html 的時候,
會根據一些順序來決定使用那一組輸出函數輸出html
否則到最後便會使用預設的template (*.tpl.php)

而node 的輸出, 會先尋找 node-[內容類型].tpl.php
所以, 我們的 node-story.tpl.php 便成為了順序中最高的排序,
使用node-story.tpl.php 輸出html, 而這template 移除了輸出作者, 日期的代碼
所以便不顯示日期, 作者了

而對於page 這內容類型, phptemplate 尋找的是 node-page.tpl.php
但garland2 之中不存在這檔案, 所以用回 node.tpl.php
便會有輸出日期, 作者的代碼了

所以, /themes/engine/phptemplate/phptemplate.engine 中的 phptemplate_node() 做了排序,
而如果你有其他想提議排序的template 的話,
但便可以用garland2 內的template.php,
使用一個 garland2_status_messages 來編制排序條件了

Comments

谢谢指教.

谢谢指教.

还以为不更新了,正

还以为不更新了,正在考虑架一个drupal的家庭网站,但是还有些模块没有,挺郁闷的

更新的確慢了點....>

更新的確慢了點....> <

不懂PHP,看着这些东

不懂PHP,看着这些东西,头都大,每每修改起来就烦

template

template 內都只是簡單的php, 用心學一兩個小時就可以了

Э

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