0

I simply want to display a table generated from an external database on a page. In researching this I found it would be easiest to do it by writing a module. Using a tutorial I created a block module that does what I want, but I can't figure out how to make a block module appear on a normal page. This must be something people do on a regular basis. This is version 7.

Is there such a thing as a page module rather than a block module?

Thanks, Jim

Just to extend this a bit, eventually I want to be able to add a select form element and perhaps write a bit of javascript (jQuery calls) to change the query that generates the table, etc. But for now just to be able to display the table on a node/page would be fine.

2
  • Not sure what you mean exactly...you can manage your blocks, including what pages they appear on, at mysite.com/admin/structure/block
    – Clive
    Feb 6, 2013 at 9:48
  • That's my point, I don't want to put data in a region I want it on the page, node 13 for instance. Thanks.
    – Jim
    Feb 6, 2013 at 9:56

3 Answers 3

1

There are a couple of ways to tackle this...

  1. If you're coding the node content yourself you can use the following snippet to get the output of a particular block into a string:

    $block = block_load($module, $delta);
    $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
    $output = render($render_array);
    
  2. There's the Block Reference module

    Defines a field type Block reference which creates a relationship to a block and allows the block to be displayed as the content of the field. It saves this relationship using the block's bid, not its delta + module.

1
  • @user1424074, it is same as my first option :)
    – Sithu
    Feb 6, 2013 at 10:52
0

You can also add the block directly in your body, using Insert Block module :

[block:name of module=delta of block]

...will insert the contents of a rendered sidebar block into the body of your node. If no delta is specified, the default block for that module will be displayed.

2
  • By 'rendered sidebar block' does that mean it has to appear in a region somewhere for it to be visible on my page?
    – Jim
    Feb 6, 2013 at 10:18
  • @user1424074, it says in the body of your node.
    – Sithu
    Feb 6, 2013 at 10:21
0

You can render a block using the following code snippet in your template file.

<?php
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
?>

The template file would be page.tpl.php for every page, but for a specific page, let's say your have a page node/13, you may have a custom page template page--node--13.tpl.php for that page.

But I think the good practice is to create a variable in hook_preprocess_page() and make it avaibable to the template. Then print it in page.tpl.php.

function MYTHEME_preprocess_page(&$variables) {
    if(isset($variables['node']) && $variables['node']->nid == 13){
        $block = module_invoke('module_name', 'block_view', 'block_delta');
        $variables['myblock'] = render($block['content']);  
    }
}

OR, another way is to use the Panel module to create a custom page in which you can create layouts and place any content such as blocks, nodes, views, forms, etc.

The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout. Integration with other systems allows you to create nodes that use this, landing pages that use this, and even override system pages such as taxonomy and the node page so that you can customize the layout of your site with very fine grained permissions.

3
  • For the future, the Panels module looks like it will be useful. Thanks
    – Jim
    Feb 6, 2013 at 10:37
  • @user1424074, Not now? :)
    – Sithu
    Feb 6, 2013 at 10:38
  • I don't currently have the time to implement it. Since the simple solution solved my current need, when I need the more complex solution, I'll investigate it more thoroughly. Thanks...
    – Jim
    Feb 6, 2013 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.