I am implementing hook_menu
and I want to render the output of one page callback
in a certain region, other than content
.
Is there a way of doing this?
Instead of defining a page via hook_menu
it is better to define a block that you can place everywhere across the site.
Is there any requirement that restricts you to using a page?
If not the following code creates a block:
/**
* Implements hook_block_info().
*/
function YOUR_MODULE_block_info() {
$blocks = array();
$blocks['YOUR_BLOCK_ABC'] = array(
'info' => t('YOUR BLOCK NAME'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function YOUR_MODULE_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'YOUR_BLOCK_ABC':
$block['subject'] = '';
$block['content'] = _YOUR_MODULE_BLOCK_ABC_CONTENT();
break;
}
return $block;
}
function _YOUR_MODULE_BLOCK_ABC_CONTENT() {
// This is where you code you use for the page goes.
return t('Hello world');
}
Code from http://kahthong.com/2013/06/create-your-own-custom-drupal-block-programmatically
You can restrict the block visibility in the block settings to only be shown on single pages. Maybe this might solve the problem. To access arguments from the current page you can use the arg function.
Cheers j
hook_menu
, but I wanted to create something directly on a certain page and I thought that was most straight way of doing it. So there is no way of forcing the output of the page callback
to a certain region, eh?
hook_menu
there's no URL defined, so the block renders on a 404 page, only based on it's visibility settings. has anyone found a workaround for this other than @Marian
I have managed to move the output from the content
region to the content_top
custom region like this:
function MYMODULE_page_alter(&$page)
{
list($path) = explode('/', current_path());
if ('shopping-list' == $path) {
$page['content']['#region'] = 'content_top';
$page['content_top'] = $page['content'];
unset($page['content']);
}
}