2013-12-09 97 views
0

我遇到了一个小问题,我无法弄清楚。 我有一个网站,将有一组将定制的页面(但与页面的模板),只是自定义内容。Drupal 7自定义页面和URI

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

我读到挂钩并提出文件 - 页面 - stuff.tpl.php和复制page.tpl.php中,而网页的标题是 - 找不到网页,我不我做的是正确的,因为复制page.tpl.php

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

我该怎么做?

回答

1

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

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 
); 
} 

可以替代themefunction有你喜欢的任何东西,但你必须实现它!

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 
} 

然后,你需要通过实施hook_theme登记在Drupal的主题(这也是在你的主模块文件DON)

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 *(在模块文件夹中):

<div><?= $items['hello']; ?></div> 

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