Insert Block into Content

mitchepa - July 23, 2007 - 13:17

Hey all, just another quick question... should be simple enough

Does anyone know how to insert a block directly into content? I looked at the php snippets section but under the snippets section for 5.0 there were only two snippets (both had nothing to do with this). I also tried using the standard php snippet that you would use to call a block in the template but that doesn't work either... what am i missing here? (If it helps I'm using the frontpage module and have it set to allow php).

Thanks everyone,
Paul

There is a module for

cog.rusty - July 23, 2007 - 13:39

There is a module for that

http://drupal.org/project/block_tags

Just to be clear, it's not

LiquidMethods - July 23, 2007 - 14:00

Just to be clear, it's not an option for you to just change in the theme where the right (or left) sidebar shows up? Possibly just putting the call to the right sidebar below the main content area could solve your problem. That is, unless you need some of the content of the page above the block and some of it below it, in which case, yes, you'll have to use the module that was just posted.

try this

jeff h - July 23, 2007 - 14:35

I think this may be what you're after -- you can put it straight into a node body (with PHP input filter):

<?php $block = module_invoke('block', 'block', 'view', 25); ?>
<h2><?php print $block['subject']; ?></h2>
<?php print $block['content']; ?>

Make sure to change the 'view' and the 25 to whatever correctly identifies the block you want to see. An easy way to find out this info is to go to your block admin page and point at the configure link for the block you want to use.

Jeff

Thank you for that code. But

norti - July 30, 2007 - 22:43

Thank you for that code. But how can I give an argument to a View (printed as a block) ???

I am not sure this will help

mariagwyn - August 11, 2007 - 01:04

I am not sure this will help you in creating a view, but what I did was create a set of views as blocks which output what I want. Then, I created a node, into which I put the following PHP code (thanks to the hint from above):

<?php
$block
= module_invoke('views', 'block', 'view', Lectures);
?>

<?php
print $block['subject'];
?>

<?php
print $block['content'];
?>

I believe this 1) invokes the views module, 2)tells it to display a block, 3)I have no idea what the second 'view' means, and 4) picks the one I have called 'Lectures.'

Hope this helps a little.
Maria

Might be wrong, but I think

dmuir - June 11, 2008 - 06:25

Might be wrong, but I think the second 'view' refers to the action. As in you're going to view the block, not edit the block.

module_invoke arguments

isaac77 - February 25, 2009 - 15:39

The arguments to module_invoke are explained at http://open.madcap.nl/fotd/module_invoke

To print a block called "foo" that is supplied by a module named "bar," I _think_ you would do this:

<?php
$block
= module_invoke('bar', 'block', 'view', 'foo');
print
$block['content'];
?>

(This is for Drupal 5.x -- not sure if anything's changed in 6.x)

Cool, that worked... thanks

mitchepa - July 27, 2007 - 19:46

Cool, that worked... thanks all ;-)

Now that I figured this out

mariagwyn - July 18, 2008 - 00:20

Now that I figured this out in drupal 5.x, I am having problems in 6.x, specifically, with views. So, here is the situation:

If I do this code:

<?php $block = module_invoke('image', 'block', 'view', 1);?>
<h2><?php print $block['subject']; ?></h2>
<?php print $block['content']; ?>

I see the random image block, works fine. However, if I do the following:

<?php $block = module_invoke('views', 'block', 'view', archive_reflections-block_1);?>
<h2><?php print $block['subject']; ?></h2>
<?php print $block['content']; ?>

Nothing shows up. I have tried every variation on the name of the block that might work, to no avail. Has something changed in Views regarding how you invoke blocks? Any ideas?

Same problem here, no matter

cflemm - August 8, 2008 - 18:05

Same problem here, no matter what I do cannot get anything to show up.

I am using Drupal 6.3 and Views 2. Has anybody been able to make this work?

I did figure this out with

mariagwyn - August 9, 2008 - 01:20

I did figure this out with Merlinofchaos' generous help, you can see the train here: http://drupal.org/node/263554

However, here is a summary:

This code embeds the view block as is. The first variable is the NAME of my view. the second is the NAME of the block. Still not quite sure how to figure out the name since it is actually called reflections_block, but views seems to give generic numbers.

<?php
 
print views_embed_view('archive_reflections', 'block_1');
?>

The code below embeds the view as well as the Title of the block. The code above only embeds the block itself, the title is a separate function.

<?php
  $view
= views_get_view('archive_reflections');
 
$view->set_display('block_1');
 
$output = $view->preview();
 
$title = $view->get_title();
  print
'<div class="title">' . $title . '</div>';
  print
$output;
?>


Be sure to use the PHP input filter on BOTH of these or nothing happens.
Hope that helps.

Maria

Got it working, thanks!

cflemm - August 18, 2008 - 16:35

Got it working, thanks!

works!

markosef - December 20, 2008 - 17:42

This works. I dont know why is it, but snippets like this ara always more flexible then actual drupal theming when u do visualy complex designed sites.

 
 

Drupal is a registered trademark of Dries Buytaert.