我是Drupal(v6)和PHP的新手,我試圖通過自定義模塊實現一些內容。我學習了一個教程,並想出瞭如何讓Drupal知道我的模塊,甚至爲我的自定義頁面註冊了一個URL。它按照我的意圖出現在導航中 - 迄今爲止非常好。從drupal 6頁面的回調中調用幷包含單獨的.php
這對我的玩具示例很有用......但對我實際打算編寫的頁面來說不太好。現在,我有這樣的:
function twtevents_menu() {
$items = array();
$items['gingerbread'] = array(
'title' => 'Gingerbread Gallery',
'page callback' => 'twtevents_gallery_gingerbread',
'access arguments' => array('access twtevents content'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
function twtevents_gallery_gingerbread() {
// content variable that will be returned for display
$page_content = '';
$page_content = '<p>'. t("Some super-cool content") .'</p>';
return $page_content;
}
但我不想在$page_content = '<p>'. t("Some super-cool content") .'</p>';
的風格來寫一個大型的,複雜的頁面 - 和和。
我想寫的風格實際的頁面更接近這一點:
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ' '. $status ?> clear-block">
<?php print $picture ?>
<?php if ($comment->new): ?>
<span class="new"><?php print $new ?></span>
<?php endif; ?>
<h3><?php print $title ?></h3>
</div>
當PHP代碼中灑入HTML標記,而不是相反。
從我的函數中,我可以成功地調用include($path)
,但是(當然)這種方法只是將我的頁面的輸出放在broser的左上角短號中...我需要發送單獨的輸出頁面作爲我的回調函數的返回值。
有沒有這個PHP函數?一個Drupal函數?最佳實踐?
謝謝!兩個答案都非常有用......希望我能夠「接受」兩者。作爲一個PHP/Drupal的newb,它的代碼示例更適合我的情況並且更加完整(顯示完整的twtevents_gallery_gingerbread()函數)。 – 2011-04-06 15:58:09