2013-12-09 96 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過濾器模塊。