Create your first Drupal 7 module with the following steps.
- Create a folder called helloworld in sites/all/modules/custom
- Create a helloworld.info file
- Create a template file page-helloworld.tpl.php in your theme directory
- Enable your module at http://domain.com/admin/build/modules
- Visit http://domain.com/helloworld
This belongs into your helloworld.info file
; $Id$ name = helloworld description = Reinholds Hello World module package = Reinholds modules core = 7.x files[] = helloworld.module
The helloworld.module file
<?php function helloworld_menu(){ $items = array(); $items['helloworld'] = array( 'title' => t('Hello world'), 'page callback' => 'helloworld_output', 'access arguments' => array('access content'), ); return $items; } /* * Display output */ function helloworld_output() { header('Content-type: text/plain; charset=UTF-8'); header('Content-Disposition: inline'); return 'helloworld'; } ?>
The theme template file page-helloworld.tpl.php
<?php print $content; ?>
its very interesting topic, , really nice & briefly explained about drupal 7 module, thank you for time spending for us..
Everything is pretty much the same like in Drupal 6.
Where i can put helloworld.module
thanks
Thanks for the great article! I hopefully can begin the long process of porting my custom modules now.
sites/all/modules/custom
very simple and nice… good work. thank you.
Yeah. Thanks
Thx too much bro for help ,,,, i m a beginner in drupal ,, nd i starts with drupal 7 from last 3 dayz ,, can you plzz provide me more documentation regarding custom module creation ,, nd theam integration ,, if u have any pdf or any other mail compatible format then plzz mail me at jatinder.data.mca@gmail.com ,,,
waiting for ur reply bro ,,,
Hey i am not getting output using this.
can you please help me.
thanks in advance…
wow! this is perfect.am now good to go.thanks
This isn’t working:
“Access denied
You are not authorized to access this page.”
Any idea what is causing this?
Elijah, did u solve ‘Access denied’ ?
Solved.
I had some error in hook_menu()
‘page callback’ => ‘say_helloworld’, // array(‘access helloworld’), // <== was 'access content' value
i know some banned restriction for path value.
then i believe most case in our code T.T.. as it.
very simple n easy………..
Thanks
Thanks a lot.
It’s very simple and easy to apply. A good first step to understand and create complex modules.
This works nicely, except that page-helloworld.tpl.php is ignored. When placed in the theme/whatever/templates folder, I can’t get it to be recognized, even after clearing the cache. Any ideas?
Looks like a typo above.
Should be:
page–helloworld.tpl.php
Notice the double hyphen. Single hyphen was for Drupal 6.
Also, for Drupal 7,
print $content;
should instead be
render($page['content']);
(another change from Drupal 6)
I would like no template, for witting something like special feed. I do not understand how to set up… “hellow world” appear in my template…..
hi dear,
where to put following contents..
thanks
Balwant Bishnoi
sites/all/module/helloworld
Thanks
Hello Reinholds,
Very short & simple. Thanks & appreciate you work for community.
It would be very good if you explain code you mention in script, that’s helps a lot to beginner.
By the way, good work & thanks from community.
Hemant
I have run the example and works fine, but I want to have it displayed as block in block list and it doesn’t seems visible. How can I have it displayed as a block?
Hi Reinholds,
Very short & simple. Thanks & appreciate you work for community.
Simple and elegant. I was searching exactly the starting point of drupal 7 module developement and here I got this Simple and effective post about it
Thanks
And now. How can I show it in drupal?
thnks.
sick write up bro, nice and clean, you sir are a scholar and a gentleman
I’m novice in drupal. This really helped me. Thanks!
To run it, you only need to enter yourdomain/helloworld
Very helpfull for begginner module developer as me.
If we see output domain/helloworld
Brilliant! Helped me a lot!
Thank u very much…its very nice for drupal developers for understand coding…..
[...] Source [...]
[...] [...]
If you don’t have Clean URLs enabled then you have to access this module at: example.com/?q=helloworld
Otherwise you will get a 404 error at example.com/helloworld