I'm slightly confused as to how I should get my content on the page from a custom module. I thought I would normally do it with the block_view hook, but apparently another way is the page callback function. While I think I understand the former, I'm not quite sure how the latter works, and what I should return from it. Should I use one or the other method? When shoul dI use which? Can I use both?
1 Answer
hook_block_view()
and hook_menu()
aren't related at all, they're two completely independent concepts.
hook_block_view()
is for defining blocks, which can be assigned to regions within the page template.
Items defined in hook_menu()
are pages, for which a page callback
is required to build up the content for that page.
I guess the slight confusion is that in Drupal 7 the page content is automatically assigned to a block in the main system region. Whatever you return from your page callback
function for a menu item will be assigned to that main system block when you access the defined page.
A block is not accessible through a URL; it is a contextual piece of information that you add to different pages/regions when you need to. Think of the shopping cart in an e-commerce site as a perfect example of a block.
A menu item defines a page that is accessible through a URL, and may well contain any number of blocks within it.