Constant Contact E-Newsletter Service - get 60 days free!

Constant Contact has been in business since 1996 is one of the most reliable and trusted email marketing services around. Click here to activate your free 60 day trial courtesy of CWD Community.

Save $50 on Dreamhost Hosting - Any Plan

As a preferred visitor, you can get $50 off of any Dreamhost hosting plan by using coupon code CWD50 when you check out, for a limited time. Dreamhost is a reliable hosting provider with solid customer service and a proven track record.



Jul 21 2008

Drupal - how to display block in node?


Filed under: Content Management Systems » Drupal,
Tools:


Learn Drupal quickly with Drupal videos

If you want to learn all about Drupal by watching easy to understand videos, you won't have to search for individual articles such as this one, which addresses how to insert a Drupal block's contents into a node. Tap into the power of Drupal, slash your production time and create better Drupal websites. These videos include the process of building a fully featured sample Drupal site from scratch. Offered by our partner and Drupal Association Organization Member, these videos are available for a limited time. Check out these exclusive Drupal Videos now.

How do I place a Drupal block's contents into a node?

There used to be a module that did this, but I forget what it's called, and am unsure as to its compatibility with various versions of Drupal. The easiest and most direct way to place the contents of a block in a page are using the following PHP snippet:

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

Placing any Drupal block within a node

In this particular example, we're displaying a menu block with ID 26 inside a page. Here's how you use this code snippet to insert any block (this example uses Drupal 5.x; for other Drupal versions, the process should be similar):

  • Browse to Site Building -> Blocks -> List
  • Browse over the "configure" link next to your block

This will reveal the following address line (in this example we are using a custom block with ID 26)

/admin/build/block/configure/block/26

the last two variables are the ones we're interested in: /block/26

This works for any content type, and any block

If we wanted to place this custom block into a page, we would simply substitute these values into our PHP code snippet (which we place in a node (page or other content type)) as follows:

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

Notice that the middle two terms ('block', 'view') always stay the same. You're simply updating the first and last term.

Voila Smiling

What if I want to display a node in a block?

For the reverse method, displaying a node (such as a page) in a block, we recommend you use the node as block module.

Learn Drupal quickly with Drupal videos

If you want to learn all about Drupal by watching easy to understand videos, you won't have to search for individual articles such as this one, which addresses how to insert a Drupal block's contents into a node. Tap into the power of Drupal, slash your production time and create better Drupal websites. These videos include the process of building a fully featured sample Drupal site from scratch. Offered by our partner and Drupal Association Organization Member, these videos are available for a limited time. Check out these exclusive Drupal Videos now.

Average: 4.2 (25 votes)
Tools:



Ok here's the deal I got a

Ok here's the deal.

I got a LAN setup at home with the internet coming to the PC assigned an IP 192.168.0.1 (my Internet server).

Now, using Internet Connection Sharing, I have shared the internet access to 2 other PCs who get an IP address dynamically (and are always OTHER than 192.168.0.1).

The thing is, I need to block access to a particular website only on 192.168.0.1 (the internet server for my LAN) - But need to have access on that site on the other machines.

I added an entry to my hosts file on the internet server 192.168.0.1 as following:

127.0.0.1 www.orkut.com

Now, when I try accessing this website via my laptop (which is NOT 192.168.0.1), it says page can not be found -- So the hosts file is functioning as expected. I need to know if there's any way I could block that site only on a particular NODE on the network without having to purchase any paid software.

Drupal over other CMS

This is why I prefer Drupal over other CMS systems such as Joomla, Wordpress, etc. - the flexibility. Not only in terms of coding and theming, but in being able to theme and adapt customizations of actual modules and core code, without disrupting the core code. In other words, being able to apply your own theme to things to get things done. Such as is the case with the simple ability of displaying a block within a node. Cheers!

Good stuff!

Good stuff!

Updated Code

Here's the updated code for embedding a block in node:

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

How to show certain block in one menu

I need to show one certain block in one menu and other block in another menu. Please any body help me.

You know, the more I got into

You know, the more I got into Drupal the more I disliked it. Now I want nothing to do with it. I hate it actually.

Mighty thanks for the snippet

Mighty thanks for the snippet. Worked like a charm Smiling

Drupal Open Source

Drupal is a powerful open source web development platform. This is easier and surely gives comfort to Internet users. Thanks for sharing. Posts like this offer a great benefit to us users.

This works great but is there a way to pass in arguments?

I have created a view that requires an argument to be passed in. Can you pass in arguments using your code? Any help is greatly appreciated! <?php
$block = module_invoke('views', 'block', 'view', 26);
print $block['content'];
?>

I tried

Thanks..

My code is like the visitor

My code is like the visitor that just posted:

configure/views/Prices-block_1

I tried using block id 1, but that did not work. I will try to figure out what its real id is... any good way to do this?

Similar Entries Module Block

I want to include my block from similar entries module, but it doesn't simply have a number, but "configure/similar/0". Any idea on how to include this block? Great post, thanks! Smiling

Try 0

Did you try 0 as the number?

My Drupal impression

I have been building my websites using Wordpress and other platforms and only recently came across Drupal. First impressions are that is has a clean presentation and is well supported with great tutorials.

Thanks

In the evening I usually save all interesting for me articles and read them either in the morning on my way to work or during the dinner break. When I fail to find free time though, I set articles in pdf format and download them.

Thanks for the snippet

Thanks for the snippet. I was trying to remember how to do that. Drupal always gives me a headache it seems.

Display suite module

The module Display Suite (DS) can do this for you.

Raghu

Hey,

Good Post. But instead of using the block id 26 can't we use the name of the block or some other parameter?

Use any id

Simply use the ID corresponding to the block you want to insert. There may be a way to do this by block name, but we haven't come across one yet.

node block

Thank you for the information on how to display block in node. Sharing these codes are really gonna be very beneficial.

drupal

Thanks for you the information on how to block drupal using drupal blocking mode.

Is this code same as in blocking a node?

Thanks for sharing this code. But one question though. Is this the same as when you place a block in a node?

Thanks again.

Globat Reviews Guy

Block in node

Yes, that's precisely what it is.

Thanks for the script!

Thanks for the script! Indeed very helpful.

Cool

Thanks for the codes. U really did a good job.

DISPLAY

If you want to display multiple nodes you can create templates for each of them.

jollie

Drupal node insert - input format?

When inserting a Drupal block within another Drupal block or node - does the input format get inherited (as with an iframe), or does the input format of the parent node override that of the inserted node or block?

Inserted content treated as iframe

Good question - the input format of the inserted node will apply to the inserted portion, while the input format of the parent node will apply to the rest of the node. In other words, the insert will be treated as an iframe.

Core Drupal developers bogged down

Most Drupal developers are bogged down getting core functionality improved. This could be a good starting point for you to contribute to Drupal.

Drupal

Thanks for the great Drupal tips, will come in very handy!

Good Drupal workaround

Makes everything looks easy with the workaround that you've shown us.

I will keep this in mind

Interesting, when I'm ready to use Drupal and experiment around with it, I think I will give this a shot. Cool. Depends what I decide to do next with my email marketing business and if that's the direction I even want to go with it.

Node-specific page template

I believe that the easiest way to do that is to use a node-specific page template. And if you want to display multiple nodes you can create templates for each of them.

Some of the blocks

Some of the blocks do not have a number on them. I made a view, but it didn't give it a number... I'm confused...

non-php version of this functionality

reptag module provides this sort of functionality through a filter.
Use markdown code like the following:

"{BLOCK:1}" => "user-defined block 1",
"{BLOCK:Contact Details}" => "user-defined block with the given title",
"{BLOCK:menu:2}" => "block 2 supplied by the named module",
"{BLOCK:image:Random image}" => "named block from the given module"

Pretty handy if you like it.

Number on drupal blocks in view?

Some of the blocks do not have a number on them. I made a view, but it didn't give it a number... I'm confused...

This is so simple, isnt there a module for this ...

i mean come on ...

Making a Drupal module

It is simple. If you want this installed as a module, why don't you learn how to create the module? Most Drupal developers are bogged down getting core functionality improved. This could be a good starting point for you to contribute to Drupal.

Drupal newbie

I like what I've read about Drupal so far and plan on experimenting around with it. In fact, I think I will give this a shot. Cool. Depends what I decide to do next with my email marketing business and if that's the direction I even want to go with it.

Thanks for the code.

Thanks for the code.

The first example does not work, because the word "menu" is there, when it should be "block".

Inserting Drupal Block vs. Menu

I probably should have made that more clear. The first example is for inserting a menu into a node, the second for inserting a block.

Placing a webform into another node - Possible?

I would like to place a webform form which is a node into a page/node. Is the code very similar to placing a block in a node?

Thanks

Rory

Appreciated

Is the code very similar to placing a block in a node?

Webform description

Hi Rory,

I'm pretty sure it's possible, but you might be better off simply inserting what you had in the other node in the description field of the webform - it will take any input format, so you should be able to put just about anything in there.

buenisimo!!!!!!!!!!!!!!!!!!

buenisimo!!!!!!!!!!!!!!!!!!
gracias

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br> <br />
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.