0

In my page--front.tpl.php i have a menu block rendered using:

<?php
$block = block_load('menu', 'menu-basic-menu');
print render(_block_get_renderable_array(_block_render_blocks(array($block))));
?> 

Which works as expected.

What should i do to print this block on all pages of a specific content type?

Help appreciated

2

You can created the page.tpl.php and put a condition to check the content type then print this block.

page.tpl.php API Drupal 7

From node object you can find the content type to check condition.

<?php print_r($node);?>

More specific to your question.

<?php global $node;
    if ( isset($node) && !empty($node) && $node->type == 'type_name') {

            $block = block_load('menu', 'menu-basic-menu');
            print render(_block_get_renderable_array(_block_render_blocks(array($block))));

    }
 ?>
  • I'd go for this solution too. – Djouuuuh Jan 15 '15 at 10:56
  • thanks The block is rendering fine. However i am getting an: "Notice: Undefined variable: node in include() (line 79 of C:....." Still working on my php skills.. – Byron Jan 16 '15 at 9:43
  • once try for global $node; – DRUPWAY Jan 16 '15 at 10:04
  • Using: <?php global $node; print_r($node);?> <?php if ( !empty($node) && $node->type == 'page') { $block = block_load('superfish', '1'); print render(_block_get_renderable_array(_block_render_blocks(array($block)))); } ?> The error is gone however the block doen't render anymore. Sorry for the markup – Byron Jan 16 '15 at 10:11
  • updated my answer. – DRUPWAY Jan 16 '15 at 10:19
0

To print my block per content type i used following code in my template file:

<?php
function themeName_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
  // If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
   $vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type);
  }
}
?>

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.