2

The error that I am getting is as follows

Strict warning: Only variables should be passed by reference in include() (line 73 of /Applications/MAMP/htdocs/.../sites/all/themes/bootstrap/templates/page.tpl.php).

The code producing this error is

<?php
$path = drupal_get_path_alias($_GET['q']);
$block = block_load('block','2');
if ($path == 'home') {
  print render(_block_get_renderable_array(_block_render_blocks(array($block))));
}
?>

I don't know why this error is coming up because the code is working perfectly.

Could anyone Helo me please?

4

The solution for this will be to do the same thing with the code below.

$region = _block_get_renderable_array(_block_render_blocks(array($block)));
print render($region); 

After changing your code make sure that you clear your cache. And try refreshing. Also make sure you have made this changes every where.

So you know what the problem is: The render() function takes a parameter by reference. In that case you must pass in a variable, not a function call, because the function call is not something that can be passed as a reference.

1

As a side note, you generally should not be calling functions that start with an underscore as they are intended to be private functions - not to be used from outside that module.

You should also be doing the block loading in a preprocess function, and only printing it in the page.tpl.php file.

The proper way to do what you are doing is this: In your template.php file:

/**
 * Implements template_preprocess_page().
 */
function bootstrap_preprocess_page(&$variables) {
  // No need to pass in the q arg, as it is the default.
  $path = drupal_get_path_alias();
  if ($path == 'home') {
    // Load the block inside the if statement so you aren't loading
    // it when you don't need it.
    $block = module_invoke('block', 'block_view', '2');
    $variables['my_block_content'] = $block['content'];
  }
}

then in your page.tpl.php:

<?php print render($my_block_content); ?>

If you really want it all in the page template, just do this:

<?php
  // No need to pass in the q arg, as it is the default.
  $path = drupal_get_path_alias();
  if ($path == 'home') {
    // Load the block inside the if statement so you aren't loading
    // it when you don't need it.
    $block = module_invoke('block', 'block_view', '2');
    print render($block['content']);
  }
?>

For more information on rendering blocks see http://drupal.org/node/26502

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.