【发布时间】:2011-04-06 06:44:45
【问题描述】:
我是 Drupal (v6) 和 PHP 的新手,我正在尝试通过自定义模块实现一些内容。我遵循了一个教程,并弄清楚了如何让 Drupal 了解我的模块,甚至为我的自定义页面注册了一个 URL。它按我的意图出现在导航中——到目前为止一切都很好。
这对于我的玩具示例非常有用……但对于我真正打算编写的页面来说不太好。现在我有这个:
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 函数?最佳做法?
【问题讨论】: