首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Drupal 7自定义页面和URI

Drupal 7自定义页面和URI
EN

Stack Overflow用户
提问于 2013-12-09 14:38:38
回答 1查看 78关注 0票数 0

我遇到了一些我搞不懂的小问题。我有一个网站,并将有一组网页,这将是定制的(但与模板的网页),只是定制内容。

例如:http://mypage.com/?q=stuff

我读到了关于挂钩并创建文件页--stuff.tpl.php和复制的page.tpl.php,但是页面标题没有找到,而且我没有做好,因为复制了page.tpl.php

这些页面将包括自定义手写模块和自定义PHP代码,但总体布局将与其他节点相同。

我怎么能这么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-09 15:44:31

若要创建未链接到节点的页面,必须在自制模块中实现菜单

代码语言:javascript
运行
复制
function MODULENAME_menu() {
  return array("stuff" => array( // link (in your case: http://mypage.com/stuff)
  'title' => "stuff", // title of the page
  'page callback' => "themefunction", // logic for the content
  'type' => MENU_CALLBACK // there are more types, read hoo_menu() for further details
  );
}

你可以用任何你喜欢的东西来代替它们,但是你必须实现它!

代码语言:javascript
运行
复制
function themefunction() {
  // do some theming output stuff like:
  $items['hello'] = "Hello World!"; // your variable output
  return theme('stuff_theme', array('items' => $items)); // say Drupal to theme that stuff in your default page-template
}

然后,您需要通过实现主题 (也就是在主模块文件中的don )在Drupal中注册主题。

代码语言:javascript
运行
复制
function MODULENAME_menu() {
  return array(
    'stuff_theme' => array( // file name of the template WITHOUT .tpl.php
      'variables' => array( 
        'items' => NULL // variables that are assigned to the template
      )
    )
  );
}

最后,您需要创建模板*stuff_theme.tpl.php* (在模块文件夹中):

代码语言:javascript
运行
复制
<div><?= $items['hello']; ?></div>

不幸的是,这是创建真正的自定义内容页面的唯一方法。对于向节点注入小代码,还可以启用PHP 模块。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20473300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档