开发者

How to append to a Drupal module page callback

开发者 https://www.devze.com 2023-01-12 11:13 出处:网络
Say you have a page callback from Module #1 using hook_menu(). You want to create Module #2 that would basically just append s开发者_开发技巧omething on the bottom of Module #1\'s page callback (think

Say you have a page callback from Module #1 using hook_menu(). You want to create Module #2 that would basically just append s开发者_开发技巧omething 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消