2

Working on a project I faced with a problem , in this project the front page looks completely different than the other pages and it consists some regions which are not exist in other pages.

Now the problem is that when I put an instance of a block in a region which only exist in front page then I cant use this block in other pages.Any idea how to solve this problem?

3

Multiblock will allow you to create multiple instances of the same block, so you can place it in different regions on different pages.

Alternatively, if the block in question is being generated by a view, you can create an additional block display.

5

As stated above you can certainly use Multiblock but the are a few other ways as well.

One is to use the Context module where you can create different contexts where any given context can render the same block or sets of blocks but with different conditions.

The other method I use is to use the module_invoke function. You could invoke the module and block in a node or page preprocess function by creating a variable for the block display and then call the variable in a node or page template. An example would be something like this:

In your theme's template.php file. This example calls the Disqus module's comment block:

/**
 * Override or insert vars into the node template.
 */
function mytheme_preprocess_node(&$vars) {

  // Define the node.
  $node = $vars['node'];
  $nodetype = $node->type;

  // View mode check (Optional).
  if ($vars['view_mode'] == 'full') {

    // Content type switch check.
    switch ($nodetype) {

      case 'blog_post':
        // Disqus comments block.
        $block = module_invoke('disqus', 'block_view', 'disqus_comments');
        $vars['block_disqus_comments'] = $block['content'];
        break;

    }
  }
}

Here we created a template variable called block_disqus_comments for use in a node template. This calls a block that was created by the Disqus module called disqus_comments. You can now call that on one region in one template and in another region within another template. We set a case of the content type blog_post but theoretically you could add other content types or conditions depending on your needs.

We then can render this in our blog node template as:

<div class="disqus-wrap">
   <?php print render($block_disqus_comments); ?>
</div>

The nice thing about either of these methods is that they can be carried forth in code and sent to your code repo via Git. (For Context, you would need the Features module to do that).

  • Panels is another option – Raf Aug 24 '16 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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