Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By rentawebguy on
I've created a new block and put my secondary links into it.
How do I display/use this block in my template?
Comments
- add a region to your
- add a region to your template
- assign the block to this region in the drupal back-end on /admin/build/blocks
- read this for more info: http://drupal.org/node/171224
module_invoke, print block snippet into your page.tpl.php
generic snippet
i.e logintoboggan block in a theme.tpl.php
Funny... consider this as
Funny... consider this as the community saying 'Welcome to Drupal!'
As you see above, there is often more than one way to do something. That's the kind of flexibility Drupal offers. Let's explain the difference between the solutions, so you don't get lost:
If you use the method with a region, a user with the right permissions can change the settings of the block in the back end. This includes changing the block title, placing it in another region, hiding it on specific pages or even disabling it completely. The module_invoke method loads the block directly into the template, so you cannot adjust settings for this block in the back end.
Can some clever person
Can some clever person explain what the third and fourth arguments of this module invoke call do ? I have looked at the API def for module_invoke but unfortunately I remain unenlightened !
Thanks
Dave
At
At http://api.drupal.org/api/function/module_invoke/6 you can read
This means that the first argument is the module name, the second argument is the hook name, all other arguments are passed on as parameters to the hook function that is being called.
To get the first and fourth parameters...
Go to the block administration page and hover over one of the "configure" links (or click on configure). The second to last argument of the URL is the "module" name that created the block and the last argument is for the fourth parameter. So for instance, I hover the "configure" link for a block I want to invoke on a template. I see the following path:
admin/build/block/configure/webformblock/71
From this I learn that the first parameter should be "webformblock" and the last parameter would be "71".
So back to the example
I fill it in for my case like this:
In this case the last argument is an integer. But it is not always the case. For example, the Views module creates blocks and places a string for that parameter like, "contentlist-block_1".
Another example then might be:
And yes, the stuff at api.drupal.org is very hard to decipher with examples.
content2zero.com
How do I hide the block from the category page?
I want the block only in the full node display.
I know I can do CSS but that way is not efficient (resources-wise).
Edit the block visibility
Edit the block visibility settings on the block configure page.
Still displayed
I put this under "display in all pages except ..." : category/*/* and category/* but neither of them worked.
Question: Is it correct that invoking a block, bypasses it's display setting?
My php script is in node.tpl.php.
There is the possibility to add IF condition to the script so it will be activate only in FULL NODE display.
I just do not speak "Druplaish" very well ...
It would help if you would
It would help if you would show your code, so I can see what exactly you are doing. Do I understand correctly that you are trying to render a block in node.tpl.php, instead of the usual page.tpl.php?
That said... Yes, if you directly invoke a block (using code like
$block = module_invoke($module, 'block', 'view', $delta);
), the visibility settings are not taken into account yet. The visibility settings do get applied when you call the theme_blocks function (see http://api.drupal.org/api/function/theme_blocks/6) which in its turn calls block_list (that's where the visibility settings are actualle handled, see http://api.drupal.org/api/function/block_list/6). What I would do is create a new region in your theme, called for instance 'in_node'. Then in your template.php you can put the following code:If that _preprocess_node function already exists, just add that single line of code to it. This will make a new variable,
$in_node
, available in your node.tpl.php. Now in your node.tpl.php you can simply do<?php print $in_node; ?>
.PS. this is all untested code, please tell me (and forgive me) if I made an error.
Thanks !!
First - you are right - I should have quoted the code but you corectly guessed: I used this code.
Your suggestion did the job, with a small correction:
The rest is as you described it.
Wonderful. Thanks for the
Wonderful. Thanks for the feedback.
thank you
thank you.... its work for me
D7 Syntax for block
$block = module_invoke('modulename', 'block_view', 'block_name');
print render($block);
-
Chintan Umarani
Drupal Developer
www.umarani.com
D7 Solution
I couldn't get the above to work, the solution I found is:
$block = block_load('views', 'block_name');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;
$block =
is working for me for views blocks...
be sure to go to the blocks admin page and get the machine name for the block from the configure URL.
Try category* You can also
Try category*
You can also set block views in context.
Use module_invoke
Try above solution.
here '$module_name' and '$delta' information u can get by hovering over the 'configuration' link just besides that block in 'admin/build/block' page
AddThis module block
This code is working perfectly for me: https://www.drupal.org/project/addthis
$addblock = module_invoke('addthis', 'block_view', 'addthis_block');
print render($addblock['content']);