2

I would like to create a full page with a custom module. I mean a page that should not reside within the larger Drupal page. How can I achieve this?

This is the code I am using.

mymodule.module

 function mymodule_menu() {
   $result = array();
   $result['mymodule'] = array(
     'title' => "Some Title",
     'page callback' => "mymodule_function",
     'access callback' => true,
     'type' => MENU_NORMAL_ITEM,
     'weight' => 1,
   );

   return $result;
}

function mymodule_function() {
  print theme('my_custom_template');
  exit; 
}   

function mymodule_theme() {
  return array(
    'my_custom_template' => array(     
      'template' => 'mymodule-page',
    ),
  );
}

mymodule-page.tpl.php

<html>
    <head>

    </head>
    <body>

        Hello World
    </body>
</html>

This works fine enough, but is this the correct method? I also wonder how I would include forms (submit data, retrieve data, display that data, etc)?

  • You are working with Drupal 7, I assume? Can you add the "7" tag? – donquixote Aug 18 '17 at 19:31
  • Similar question: drupal.stackexchange.com/questions/38576/… – donquixote Aug 18 '17 at 19:38
  • Oh, actually this one has a good answer: drupal.stackexchange.com/questions/4046/… Use a custom page delivery callback! – donquixote Aug 18 '17 at 19:39
  • Hello. I've added Drupal 7 to my question. I have looked at the the second suggestion, but as I am new to this, I had a hard time following what was being discussed. Do you have any example code? – jason Aug 18 '17 at 19:45
  • 1
    Maybe you could further specify your use case: You say "it should not reside within the larger Drupal page". Why? You don't want the blocks, sidebar, header etc? What is the purpose of this page? – donquixote Aug 18 '17 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.