dongmi4809 2013-12-09 14:38
浏览 84
已采纳

Drupal 7自定义页面和URI

I encountered small problem which I cant figure out. I have a website, and there will be set of pages which will be custom made ( but with template of the page ), just the custom content.

For example: http://mypage.com/?q=stuff

I read about hooking and made file - page--stuff.tpl.php and duplicated page.tpl.php, but page title is - Page not found and i don't i'm doing it right, because of duplicating page.tpl.php

Those pages will include custom hand written modules and custom PHP code, but overall layout will be same as other nodes.

How i could do this?

  • 写回答

1条回答 默认 最新

  • dou7466 2013-12-09 15:44
    关注

    To create a page which is not linked to a node you have to implement hook_menu in a self-made module.

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

    You can substitute themefunction with anything you like, but you have to implement it!

    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
    }
    

    Then you need to register your theme in Drupal by implementing hook_theme (that is also don in your main module file)

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

    Finally you need to create the template *stuff_theme.tpl.php* (in the module-folder):

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

    Unfortunately that's the only way to create truly custom content-pages. For small code-injections into a node you can also enable the PHP filter module.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!