Simple way to embed blocks into content

underpressure - August 6, 2007 - 00:07

Is there a simple way to embed a block into content?

I've found ways using regions and some other ways but the blocks created do not div tags are not exact to those in the side bars.

Is there anyway you could use something as simple as:

<?php
block
=(block ID);
?>
I don't know PHP but to custom embed a ad banner is similar.

I remember there was a

drupalina - August 6, 2007 - 00:12

I remember there was a module that said it did exactly that: put blocks into content. I don't remember the name exactly ... it was something like BlockPage or BlockNode or NodeBolock or something like that.

If you come up with an easy solution that works optimally please post it back here, so that others will benefit as well.

I remember there was a

drupalina - August 6, 2007 - 00:13

I remember there was a module that said it did exactly that: put blocks into content. I don't remember the name exactly ... it was something like BlockPage or BlockNode or NodeBolock or something like that.

If you come up with an easy solution please post it back here, so that others will benefit as well.

Insert_block

underpressure - August 7, 2007 - 20:24

I haven't looked at the modules list yet but I did find one called Insert_block that can do the job will let you know once I've tried it.

Example

Michelle - August 6, 2007 - 00:32

$block = module_invoke('nice_menus', 'block', 'view', 1);
print $block['content'];

Michelle

--------------------------------------
My site: http://shellmultimedia.com

I found a similar snippet

underpressure - August 7, 2007 - 16:41

I found a similar snippet before I started this threat. What I wanted was something that created all the css tags like the default black design.

I Found this one but I haven't tried it yet:

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

I think it would work but still missing the div and class tags, right?

What are the module_invoke

Aren Cambre - September 11, 2007 - 21:02

What are the module_invoke parameters? http://api.drupal.org/?q=api/function/module_invoke/HEAD just explains the first two.

Module_invoke

Muslim guy - September 30, 2007 - 14:17

Example is the Guestbook

<?php
 
if(!$user->guestbook_status){  // guestbook_status seems to store 0 for enabled and 1 for disabled
    
print module_invoke('guestbook', 'page', $user->uid);
  }
?>

I think I want to place this in a block, I will let you know if it works or it wrecks :)

That code looks familiar... :)

Michelle - September 30, 2007 - 16:08

Make sure you do a "global $user" before that code or it won't know what $user is.

Michelle

--------------------------------------
Drupal articles and tutorials: http://shellmultimedia.com
Current project: http://couleeregiononline.com/

Placing Block into Content

katris - August 6, 2007 - 13:59

If you don't want to work through creating new regions a module that may help you is the Panels module.
It allows a nice ui to drop your blocks and views into the main content region of the site. The only catch is that if you need a unique panel layout you will need to modify or add new panel output templates. At any rate its worth a look.
Hope this helps.
JK

Panels Module: http://drupal.org/project/panels

ok

underpressure - August 7, 2007 - 20:21

Looked at it and it's not the best solution for what I want. I think this might be handy for me in the future. It's would certainly be great for a news oriented website.

I think some module specific templates for this module would be great.

Pass a block region into node.tpl.php

jwolf - August 6, 2007 - 14:59

Nick Lewis has an excellent post on how to create block regions for node.tpl.php

http://www.nicklewis.org/node/846

Although it is for Drupal 4.7.x, you can easily modify for Drupal 5.x
For example, if you have a custom content type, you can pass the block region into your custom content type (e.g., node-customcontenttype.tpl.php) instead of the all encompassing node.tpl.php

Got that right now

underpressure - August 7, 2007 - 20:15

My current design has that but when you want to do a lot of custom pages I don't think this is the best way to go.

It leads to a lot of PHP code and .css in single files.

I think anyone who is interested in using regions should take a look at the Panels.module is MAY be a better solution for their needs.

Thanks to jwolf for the nice

katris - August 8, 2007 - 14:39

Thanks to jwolf for the nice reference link.

I believe that the most Drupal way to go about assigning blocks to specific positions within content is to create as few unique regions as you will need in your template.php file (http://drupal.org/node/29139). Then you can output these regions wherever you want in unique tpl.php files. Although I could be incorrect about this.
It probably takes a little more php work than you want to use, but in this Drupal world its hard to avoid php and I believe that you will inevitably be pulled into the code...lol.

This being said... if you do define say... 1 region which you want to place within your content. You can re-use this region in multiple tpl.php files and in different places or assign the position via a var in one tpl.php file. This way you don't end up defining numerous regions which you are only using once on different pages.
This is important, because Drupal will process all of your specified regions regardless if they are being output to the browser and this can bump up your overhead if you have a lot of them.

When it comes to styles you can assign unique class id's or import a new style sheet to display your unique page how you want using drupal_add_css() function: http://api.drupal.org/api/function/drupal_add_css/5

I hope this helps,
JK

Gonna make a post about

underpressure - August 8, 2007 - 17:48

Gonna make a post about Insert_block.module and see it anyone responds. I tried contacting the maintainer and someone who apparently got it to work.

regions can work. I know this because I'm already using it. But I think it's not elegant when you have many .tpl files.

if you have 25 template files for various nodes e.g. photos/weblinks/news/and so on and all show different block on different parts of the page it equals to a lot more coding than I would like.

If I can get simple block fixed I will have no choice but to use regions since I thinks its the best of the rest.

I know this post is old but

techguy10 - April 5, 2008 - 00:06

I know this post is old but anyways has anyone heard anything more about the insert_block module, is it possible to get it to work? Placing blocks within the content is such a key thing for web advertising I'm surprised more people aren't interested in this as this is the only post I could find about this topic other than the tutorials to embed additional regions.

To wrap this up

techguy10 - April 5, 2008 - 18:05

So after some serious searching I finally realized that there is a module for this, the advertisement module, I hate to see posts like this left unsolved so for future reference: http://drupal.org/project/ad this should do everything related to what the people in this thread were discussing.

simple way to embed a block into content

drupalgeek - April 9, 2008 - 10:04

Yes ofcourse there is a simpler way to embed a block into content :

please use the below code :

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

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

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

Where 2nd 'block' is the module name
and replace 25 with block i.d.

Drupalgeek
Ebizon technologies ( http://ebizontek.com/)
India

Great thread! But how would

dzynz - April 10, 2008 - 00:08

Great thread! But how would one embed a block that is produced by the Views module?

simple way to embed a block into content

rdsmith@drupal.org - April 21, 2008 - 21:41

I have something along the same lines as you except in my site I would script

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

Where 1st 'block' is the module name
and replace 25 with block i.d.

Robert D. Smith

I don't think that would matter as long as the array saw the perimeters 'block' , 'view' in there somewhere, could one define the array $block as so....

$block = module_invoke('modulename', 'block' , 'view', block#);
as well as
$block = module_invoke('block' , 'modulename', 'view', block#);

module name needs to be first

philsward - January 10, 2009 - 05:06

After running across this page and attempting to implement it, I could not for the life of me get a D6 install it to work with:

<?php
$block
= module_invoke('block', 'modulename' , 'view', 25);
?>

It wasn't until I put the modulename first that it began working for me. Like so:

<?php
$block
= module_invoke('modulename', 'block' , 'view', 25);
?>

simple way to embed a block into content

drupalgeek - April 10, 2008 - 05:06

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

to embedd block from views

drupalgeek
Ebizon technologies (http://ebizontek.com)
India
Recent Projects: (kickwork, Znips)

Thanks! But where do you get

dzynz - April 10, 2008 - 21:27

Thanks! But where do you get the id number from?

answer to ur question ....

drupalgeek - April 11, 2008 - 06:43

well, to get the block id. please follow the steps below :

firstly, enable ur block in any region .

secondly , copy the code frm programming , pls see the link

http://www.programmingbulls.com/drupal-important-debugging-php-snippet-w...

thirdly , go to this link n copy the code in ur block.tpl n replace $ form with $ block

Lastly it will display all the blocks in the array form
You will get the block id frm the array.

Drupal geek
Ebizon technologies (http://ebizontek.com)
India
Recent Projects: (kickwork, Znips)

please tell me theres an

fuquam - April 22, 2008 - 21:13

please tell me theres an easier to find a block id number? Is it in a file or database? Where is it generated from?

I was glad to find this

webthingee - May 5, 2008 - 03:28

I'd call this an easy way to find the block name and id...

Blocks are uniquely identified by the combination of "module name", "block id" (relative to module), and "theme name". There is not singular block id like there are for nodes/menus/etc....

If you go to Administer/Blocks and hover over the "configure" link for the block you want, you will see the "module name" and "block id" at the end of the URL.

details at this post: http://drupal.org/node/74384

Thanks for the excellent tip

sidharth_k - October 16, 2008 - 23:04

In Drupal 6.5, for me it worked in the following way:

<?php $block = module_invoke('panels_mini' ,'block', 'view', 6); ?>
<?php print $block['subject']; ?>
<?php print $block['content']; ?>

Notice that the name of the module (depends on your needs, but in this example) 'panel_mini' comes first

I'm trying to get this

parkej60 - November 6, 2008 - 16:25

I'm trying to get this module_invoke to work with a user created menu. I've tried everything and can't seem to get it to work. This is the code that I'm using.

<?php
$block
=module_invoke('menu','block','view',menu-name);
print
$block['content'];
?>

menu-name is whatever the name of the menu is. It seems as though in Drupal 6 the menus aren't given ID's but names instead. Please let me know if you have a solution.

it worked for me in drupal 6.6

geniekids - December 2, 2008 - 10:02

you are almost there - atleast as per what is working for me
in my case the block module is 'menu' and the block name is 'menu-resources'
hope you are putting everything in single quotes like my working example below


<?php
$block
= module_invoke('menu', 'block', 'view', 'menu-resources');
print
$block['content'];
?>

see this live at
http://geniekids.com/resources
all the links you see in the node are from the BLOCK resources which incidentally is also visible in the right-bar

to have proper div tags, try

ve1itas - January 2, 2009 - 04:50

to have proper div tags, try this:

//from http://drupal.org/node/51900
$module = 'frontnews';
$delta = 0;
$block = (object) module_invoke($module, 'block', 'view', $delta);
$block->module = $module;
$block->delta = $delta;
echo theme('block', $block);

subscribing

lelizondob - March 20, 2009 - 10:01

subscribing

Luis

subscribe

jjma - March 20, 2009 - 11:18

subscribe

Doing divs yourself...

916Designs - March 30, 2009 - 02:10

The block content comes with inner div tags, we just need to add the outer ones. Consider closing (and restarting) your node's content div to keep your css selectors working..

This example shows a block created with views, on drupal 6.7-6.9 or so...

<?php
             
print '<div class="block block-views" id="block-views-explore_menu-block_1">
<div class="blockwrap">'
;
             
$block = module_invoke('views','block', 'view','explore_menu-block_1');
              print
'<h2>'.$block['subject'].'</h2>';
              print
$block['content'];
              print
'</div></div>';


?>

How would you specify Roles?

gkunstman - May 15, 2009 - 02:07

Hello
I am new to Drupal and would appreciate any assistance I could get. I tried searching for the answer but couldn't find it. I want to know how you would make a block visible to specific roles when embedding the block into content. I specified what roles could see the block when creating the block, but when I embed the block into a content page the block appears to all roles and not just the ones I specified in the block. I used the following snipplet.

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

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

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

Any help is appreciated. Thx

I think you can load the user

lelizondob - May 15, 2009 - 04:50

I think you can load the user and then make something if the user belongs to some role..

global $user;
if ($user->role[4]) {
  // do something
}

Luis

Thx... I think i've got.

gkunstman - May 15, 2009 - 18:03

Thanks for the fast response. I played with it a bit and used

<?php
global $user;
if(
is_array($user->roles) && in_array('anonymous user', $user->roles))

{
$block = module_invoke('block' ,'block', 'view', 2);
print
$block['subject'];
print
$block['content']; }
?>

and it works.

Getting the block translation?

pnee - January 2, 2010 - 20:29

I am using module_invoke to display a block in a page. This is a multilingual site and I would like to automatically display the correct translation of the block. Is there a way to accomplish this?

 
 

Drupal is a registered trademark of Dries Buytaert.