Tuesday, Jan 15th, 2013
The Node, Views and Panels modules can (and should!) handle most pages you need on a site, but sometimes you need complete control of a "hard coded" content area. You could create a new Page node with a Full HTML text format. Instead, how about putting the whole thing in code? Your work will be in version control and much more straightforward to maintain. Imagine editing HTML in a text editor rather than in the Drupal admin! So much better. Additionally, this method allows you to work more easily in a git-based workflow, such as those used by Pantheon or Acquia, without worrying about database changes.
Warnings for the less experienced Drupal site builder: This is specifically written to enforce the theme and logic separation functionality Drupal provides; no logic in the tpl files! If you can make a page in Views, it should be in Views. If you can make it in Panels, it should be in Panels. Do not use this method to recreate the wheel. If you find yourself writing large amounts of SQL queries in the page callback, then you are probably doing something wrong. Do it the "Drupal Way." Your life will be less stressful in the long run. /rant
Ok! Let's get to the code. First thing, make an info file for new module. Be sure to change the "variables" below to match your site and the page/app name.
name = Site Name - Page Name description = Creates the Page Name for the Site Name core = 7.x package = Site Name version = 7.x-1.0
Then make the module with hook_menu(), a page callback, hook_theme(), and a preprocess function.
Finally, make the template file.
<strong><?php print $hello;?> <?php print $world;?></strong>
Put the module and code in $DRUPAL_ROOT/sites/all/module/custom/sitename_pagename/. Enable your new module and check the new page at: sitename.com/page-path/
Update 7/5/13: New article using this method to implement a template file for a custom block with an admin page to manage it: Instead, how about a Drupal block with a custom settings form?
Jonathan-David ... replied on Permalink
Thanks man !!
Saxon replied on Permalink
Thanks a lot! Really helped out!
edgar-alexander replied on Permalink
Gracias, información muy buena.
Thanks, information very good.
Tarun Nagpal replied on Permalink
nikhilanant replied on Permalink
Error: syntax error, unexpected '(', expecting ')' in
brad replied on Permalink
What is the rest of this error message?
sunil kumar replied on Permalink
good hope, thankyou.
Colin replied on Permalink
Thanks for this great tutorial.
Wondering, how would one load an existing template within the current theme?
i.e page.tpl.php or page--front.tpl.php
I have a url which passes variables to the front page, which is why I am loading the page again but on a different url.
Thx in advance
brad replied on Permalink
I don't understand why you would reload the page to access variables... Can you explain further (if you haven't already solved this issue)