views:

14

answers:

2

Say you have a page callback from Module #1 using hook_menu(). You want to create Module #2 that would basically just append something on the bottom of Module #1's page callback (think of having some notes you wanted to add to the bottom of the page). How could you do this? My understanding is that you could use hook_menu_alter to completely override the page callback, but what if you just want to append to it?

+2  A: 

You can't do what you ask, but in a way you can still do it.

Say original page callback is foo

You change it to bar with hook_menu_alter.

Then you could do something like this.

function bar() {
  $output = foo();
  $output .= 'extra';
  return $output;
}

This is not a pretty solution, but it works.

Alternative solutions would be to use blocks and regions, that is what it was meant for after all. In some cases that will produce some extra work, if you need to access contexts and the block admin page and become a bit messy if you need lots of blocks for each page.

In some cases, you can fix your needs by overriding theme functions, templates or using preprocess hooks.

googletorp
That would work, but as you said, its not great since it violates a modular design. For instance, it would fail if the function name foo() changes. I'll have to rethink my design approach.
stotastic
A: 

Maybe consider implementing a default-enabled footer region block? Or using hook_footer()?

Dave Reid

related questions