Problem: I am requesting complete code for a "helloworld" module in Drupal 6 (D 7 optional, if you can do that also, fine).
Specification:
* The module shall be a standard Drupal module.
* When the user navigates to [ http://mydrupalsiteexample.com/helloworld ] the module shall output "helloworld" *and nothing else*
* The content of "View Source" in the browser shall be *completely blank* with no theme, no blocks, no css, no comments, no nothing; just a white screen with "helloworld"
* The module shall be a member of the HelloWorldTest package
* The module shall be coded with the fewest lines possible to accomplish this output
* The module shall be commented
* The module shall explain if any "tricks" were used that are not part of the standard Drupal API
* The module shall be released to the public domain
Offer:
Name your price. If you do it for free I will offer a trade or a donation to your Amazon.com account or something similar.
Disclaimer:
This is not a joke. This is a simple request in hopes to see the different ways people would accomplish this in Drupal. It is also a starting point to test out what kind of services can be purchased here in comparison to elsewhere. Depending on the result, there may be future requests for more advanced services. Thank you.
Comments
That's a minor adjustment of
That's a minor adjustment of something I did before on http://drupal.org/node/354910#comment-1186793.
Module code (save in folder 'helloworld' as 'helloworld.module'):
Info file (save in folder 'helloworld' as 'helloworld.info'):
I don't need to be paid, please donate whatever it's worth to you to the Drupal Association: http://association.drupal.org/civicrm/contribute/transact
thanks, with a couple of replies ...
1) that link you gave me to association.drupal.org does not seem to work, the result is ...
2) Thanks for your reply, I must admit I never considered simply exiting from php. Do you
know of a way to accomplish this *without* simply shutting down php entirely?
This is the right solution
Good job on the helloworld module.. that is exactly what I would have done as well.
Based on your request of outputting a page with no theme applied to it... this is the clean way to do it.
Some web applications need an output page referenced by a url that doesnt return any theme data similar to this and this is always how we did it.
This is the link to the Donate button on a.d.o
http://association.drupal.org/civicrm/contribute/transact?reset=1&id=8
It would be nice to turn this into a module in the library maybe?
Best regards,
_Dan
I feel like an idiot for
I feel like an idiot for asking this, but how do you test to see this module work? Noob here.
Thanks,
Zee
12345
1. create a folder 'helloworld' in sites/all/modules
2. create the helloworld.module file
3. create the helloworld.info file
4. visit yoursite.com/admin/build/modules on your site and enable the module
5. visit yoursite.com/helloworld
Thanks got it to work. But
Thanks got it to work. But why isn't the menu appearing in the site configuration? Unless I'm doing something completely wrong.
Thanks,
Zee
It doesn't appear in the site
It doesn't appear in the site navigation. This module is meant to be the simplest module possible. Therefore it does not publish a visible menu item. The hook_menu uses
'type' => MENU_CALLBACK,which means that is just links a path to a function, nothing more.Improved ...
Here is an improved version.
The info file looks like this:
Some extra items in hook_menu() are removed, since the default is adequate. Also proper HTTP headers are sent.
There are pros and cons when exiting early. Pros are less load on the server, but cons include cleanup and housekeeping tasks are skipped. For example, hook_exit() does not fire, so you don't get statistics, session updating and other things.
So, it is better to do something like this:
Then in your theme directory create a file called page-helloworld.tpl.php with this in it:
print $content;That is it! That theme file will be called for that path, and it has no HTML in it, so only what is returned from the function is displayed!
Here is where you can donate to the Drupal project please.
--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba
Thanks Khalid for your more
Thanks Khalid for your more sophisticated version, good point about the headers and hook_exit.
I think it's good to mention that the print-and-exit method is usually used when you want Drupal to return something like XML or json. This method is also used in the Drupal core, for instance in system_date_time_lookup, however it's nicer to run it through drupal_json(), like user_autocomplete does. (By the way, note that drupal_json does not explicitly exit... I wonder what happens when a menu callback does not return anything, but doesn't exit either.)