Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By underpressure on
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: block=(block ID);
I don't know PHP but to custom embed a ad banner is similar.
Comments
I remember there was a
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
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
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
$block = module_invoke('nice_menus', 'block', 'view', 1);
print $block['content'];
Michelle
--------------------------------------
My site: http://shellmultimedia.com
I found a similar snippet
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:
I think it would work but still missing the div and class tags, right?
What are the module_invoke
What are the module_invoke parameters? http://api.drupal.org/?q=api/function/module_invoke/HEAD just explains the first two.
theme
Try something like print theme('block',$block);
Module_invoke
Example is the Guestbook
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... :)
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
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
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
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
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
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
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
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
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
Yes ofcourse there is a simpler way to embed a block into content :
please use the below code :
$block = module_invoke('block', 'block' , 'view', 25);
print $block['subject'];
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
Great thread! But how would one embed a block that is produced by the Views module?
simple way to embed a block into content
I have something along the same lines as you except in my site I would script
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
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:
It wasn't until I put the modulename first that it began working for me. Like so:
simple way to embed a block into content
to embedd block from views
drupalgeek
Ebizon technologies (http://ebizontek.com)
India
Recent Projects: (kickwork, Znips)
Thanks! But where do you get
Thanks! But where do you get the id number from?
answer to ur question ....
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
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
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
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
Perhaps to help some others
Perhaps to help some others looking for the answer to how to embed a view block into a node, this works.
A block-view inserted into a node. "accordion_menu-block_1" is what is shown on hover over the config item.
Passing arguments to a view?
Does anyone know if there is a way to pass one or more arguments to a view using this method? Just tacking it on does not seem to work.
What I want to work:
...but it does not.
TIA!
Solution!
Found the function views_embed_view($name, $display_id)
Extra arguments get passed to the view.
I hope this helps someone else :-)
oh yeh!
That helped me out. Thanks for posting.
This got a problem I had not being able to embed a region into a node.tpl file in Drupal 7.
A problem I've been bashing my head against for several hourz I might add :)
Exactly what I needed.
Thanks!
I'm trying to get this
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.
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
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
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
Thanks!
That was what I needed, geniekids. (I was missing the quotes around the block ID.) Thanks!!!
Works fine but...
I use this code and works reallly fine... If I want to add a block to my template I have two ways, first directly all the code:
If I want to add a block without subject or with a css then I use:
If I want to place a menu I use:
in this example I'm extracting the name of the user... works cool.
And if I want to open a View block and show it, I use:
this works fine, but no matter what I use, I have 2 problems:
1.- First of all, I need to place all the blocks in a region, the region will not show anything I place there, only works to load the css in his place because If I don't make this the css will not load and see ugly... Do you have another solution???
2.- This method make that I show any of this in all the site, but how can I specify that will show only in the < front > page or in the node/15 or something like this???
Do you have any idea???
Regards
Bruno Chávez
to have proper div tags, try
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
subscribing
Luis
subscribe
subscribe
sub
subscribing
Doing divs yourself...
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...
I found Velitas' version of
I found Velitas' version of the code the easiest in this thread to reproduce block standard behaviour via PHP in Drupal 6.
Be aware that it bypasses any "title" set in block config, i. e. "".
How would you specify Roles?
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.
$block = module_invoke('block' ,'block', 'view', 2);
print $block['subject'];
print $block['content'];
Any help is appreciated. Thx
I think you can load the user
I think you can load the user and then make something if the user belongs to some role..
Luis
Thx... I think i've got.
Thanks for the fast response. I played with it a bit and used
and it works.
Getting the block translation?
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?
subscribed
subscribed
Control height of the block?
I'm a complete newbie to php, so forgive me. But, using the embed code here, is there a way to control the height of the block?
You can use css. Use one of
You can use css. Use one of the good snippets above to put a div around the block with a class or id.
Then in a css file give it a height or min-height.
.inner-content-block-1 {
min-height: 100px;
}
This is riddled with typos so
This is riddled with typos so I wanted to repost for anyone that cares.
Thanks for this!
Exactly what I needed.
Embed a Views Block Anywhere with a Views Argument
To embed a Views2 block anywhere, you can extend this by passing the arguments for the view.
Case study:
I have a view that contains the header content for a particular now. It has images, a title, and a fivestar widget. I call the view "show_header." To make show_header unique to a node (i.e. have a unique title, fivestar widget, and images, I pass that view one argument, the node id (nid).
In this example, the $arg is node #75, or just 75 in Drupal speak.
So, to pass that nid to module_invoke as the 5th argument:
Now, in my node.tpl.php I have an array called $show_header with two values, content and subject. To print them out, do this in node.tpl.php:
Note that there are FIVE (5) args sent to module_invoke. It works.
Joe Hyde
http://www.hydeinteractive.com/
Local News Platform Built on Drupal
http://sanangelolive.com/
Passing through the theme layer, so as to include title, etc.
To get a block output closer to the real thing, you should cast the module_invoke call as an object and pass it through the theming layer. This is very close to normal block output (with region counts, etc.) except that the block delta is not set and the block id comes out as id="block--" but other that that I believe it's complete and better than just outputting the content and subject manually.
If you want to have the block delta set properly you can accomplish it totally in the theming layer (no hacks) with template.php and block.tpl.php. Read more: http://drupal.org/node/753516#comment-2769068
Requesting tweaks for this specific example
Here's the block address from the configure link (all after the domain name):
?q=admin/build/block/configure/aggregator/category-4
Here's the code I've tried in the body of a Story node:
Only the straight php code shows and not the block content in the Story body. I'm using Drupal 6. Please tell me what I need to tweak.
Thanks,
Mark
None of these methods work
None of these methods work for D7 anymore. I found the best way is to create a custom region for node.tpl and do something like
print render(block_get_blocks_by_region('region_containing_block'));
Or use hook_page_alter(&$page) - but currently I have no idea how to use it. not much documentation.
module_invoke changed in Drupal 7
In Drupal 7 the 2 middle arguments that never changed: block and view "merged" into block_view.
Drupal 6:
$block = module_invoke('block', 'block', 'view', 'block_name');
Drupal 7:
$block = module_invoke('block', 'block_view', 'block_name');
Trying to get my menublock
Trying to get my menublock but it's not really working out:
Neither does
Any input?
If the module is menu then
If the module is menu then put menu instead of menu_block.
The first argument is the module generating the block and the third is the name of the block.
I think the module is system,
I think the module is system, not menu, at least that's my conclusion from the html markup D7 returns in a block.
You could also try this.
I took that code from api.drupal.org but I just don't remember exactly from where.
Here is another interesting comment http://api.drupal.org/api/drupal/includes--module.inc/function/module_in...
Luis
Solution in duplicate D7 thread
http://drupal.org/node/1034524#comment-4151036
This is a great thread.
I implemented the following:
And straight away my server load hit the roof - is their any known performance issue with module_invoke on a D6 site?
Different code for D6 and D7
I didn't read through the whole thread so I apologize if this is redundant. But it takes slightly different syntax for D6 or D7 to hardcode a block with PHP in content or anywhere for that matter.
D6:
D7:
This prints the search form anywhere, simply change the "search" to any MODULENAME and change "form" to any BLOCK_ID. you can find these at the end of the URL while you are in Structure ---> Blocks ---> Configure (desired block to print).
The end will look like this in D6: modulename/block_id
In D7: modulename/block_id/configure (just ignore the configure on the end)
Subscribe. I will try it.
Subscribe. I will try it. Thanks.
Block's visibility
Is possible to keep the visibility properties from the block??
I am using Drupal 6 with this code in the content template:
my result is that all the content that is created have this block, but the block should be only able in those pages that I allowed on the block's configuration.
How can I do that?
Thanks in advance.