To me it seems that we're a bit limited in controlling the positioning of specific blocks in themes. Yes we can define the location of regions, but beyond that, it doesn't seem you have much else control. (I know you can theme the output of specific or general blocks, but I'm talking more the positioning on the page). Am I missing something here?
For example, on the front page, I might want to have a bunch of different blocks (in the content area) in two different columns (blocks might include news, upcoming events, recent minutes, etc). Would each column have to be a different region? And then on different pages (or content types, etc) I wanted to have different blocks except in a sidebar. This could be a different region, but what if I wanted to have one common block, such as the news block. If it already belonged to the "front_bottom_left" region, then it can't also belong to the "left_sidebar" region too, right?
It would seem very useful to me if we could print specific blocks in the theme, just like we print specific regions, like...
<?
if ($blocks['block_name']) {
print $blocks['block_name'];
}
?>
...or something like that. But I don't believe that's possible.
What is the best way of arranging blocks besides creating a huge number of regions, especially with different arrangements based on node or content type? And what if a block needs to be displayed in multiple arrangements / regions?
Thanks so much!
Comments
...
You can print blocks directly, google more :) There's even a handbook page about this, http://drupal.org/node/499274, so yeah, rtm man ;)
What you loose is the ability to easily move a block, if thats not a problem then do it.
Panels and Context modules can overcome the one block/one region problem.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks for the reply! I found
Thanks for the reply!
I found something like this:
Is this what you were talking about? It does work, except this is part of the code output...
...so there seems to be a problem creating the block id. Is this what is supposed to happen?
I will also look into Panels and Context more.
Thanks!
...
The class is missing also
block-
, not sure why its not there. Will investigate... what theme are you using?FWIW you can print just the content of the block:
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
This was in Garland. I'm in
This was in Garland. I'm in the middle of developing my own theme, so it'll eventually be used in there, but it's not ready to be used yet.
Solution
I believe I found the source of the problem. The default template for blocks (modules/system/block.tpl.php) includes this line...
...but the module_invoke() function retrieves an object that only contains subject and content. Since the module and delta are both included in the module_invoke() arguments, you can just add those to the object.
For anyone else who sees this, here's a simple function that can be put in template.php to do this:
Then in template files you can simply do something like:
Also notice the delta for a block created by Views - it's not just a number. It's [View name]-block_[block number].
Thank you Jeff for your help!
Nice one adam, thanks for
Nice one adam, thanks for posting back your solution!
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
I have been playing with
I have been playing with Panels a bit, and I get the general idea but am having one problem. For some reason, blocks are not showing in panels, whether they're system or module blocks (like Who's Online) or ones generated by a View. There is just blank space in the block's place. Navigation menus and such work, but not blocks. Any ideas? Thanks!
Nevermind.... I think I
Nevermind.... I think I solved the inserting block issue (see above) so I don't think I'm going to use Panels in this site anyways... maybe one in the future because they do look very promising.