finding blocks and getting them simpler.
Hello list, One thing that has bothered me for a long time, is how to get/find/parse blocks in a simple way. Problems are: * you need to read the code to find the "delta". Modules like views require you to hover the admin/blocks/edit links in order to find the delta. * a block returned by hook_block('view') needs casting and remodelling before I can be passed to theme_block. I addressed the last point with a helper function get_block. But that function still has the first problem above: You need to know a) the module that makes the block and b) the delta. Does anyone know a trick for this? Or did I miss an API function? Is someone working on code for this? NOTE: I am not particularly interested in a discussion to revise the core block architecture. Eventhough that might be an interesting project, I am looking for an intermediate function/api-set right now :) Bèr
On 5/15/06, Bèr Kessels <ber@webschuur.com> wrote:
Hello list,
One thing that has bothered me for a long time, is how to get/find/parse blocks in a simple way.
Problems are: * you need to read the code to find the "delta". Modules like views require you to hover the admin/blocks/edit links in order to find the delta. * a block returned by hook_block('view') needs casting and remodelling before I can be passed to theme_block.
I addressed the last point with a helper function get_block.
But that function still has the first problem above: You need to know a) the module that makes the block and b) the delta.
Does anyone know a trick for this? Or did I miss an API function? Is someone working on code for this?
NOTE: I am not particularly interested in a discussion to revise the core block architecture. Eventhough that might be an interesting project, I am looking for an intermediate function/api-set right now :)
Initially, I used flexiblock to get the blocks I wanted where I want them (e.g. adsense blocks), Later, I decided that less dependancies is better, and to do it directly from core. In 4.7, there is the block regions stuff, which should work great (more on that below). Like Ber and Merlin, I find myself using the delta too. In template.php, I find myself doing this: function phptemplate_get_block($block_id) { $block = block_block('view', $block_id); return $block['content']; } Then in node/page.tpl.php I do: <?php print phptemplate_get_block(6); ?> Not pretty, and has hard coded block deltas, but it works. The reason is, I don't want the block title to be displayed. I know that this can be handled with CSS, but prefer not to have it altogether. So on my to do list, there is a task to make it an option to turn off the display of a block's title. Now that block regions can be anywhere, they can be in all sorts of crazy places. In such situations, the display of the title should be turned off for the region.
On 5/15/06, Khalid B <kb@2bits.com> wrote:
On 5/15/06, Bèr Kessels <ber@webschuur.com> wrote:
Hello list,
One thing that has bothered me for a long time, is how to get/find/parse blocks in a simple way.
Problems are: * you need to read the code to find the "delta". Modules like views require you to hover the admin/blocks/edit links in order to find the delta. * a block returned by hook_block('view') needs casting and remodelling before I can be passed to theme_block.
I addressed the last point with a helper function get_block.
But that function still has the first problem above: You need to know a) the module that makes the block and b) the delta.
Does anyone know a trick for this? Or did I miss an API function? Is someone working on code for this?
NOTE: I am not particularly interested in a discussion to revise the core block architecture. Eventhough that might be an interesting project, I am looking for an intermediate function/api-set right now :)
Initially, I used flexiblock to get the blocks I wanted where I want them (e.g. adsense blocks),
Later, I decided that less dependancies is better, and to do it directly from core.
In 4.7, there is the block regions stuff, which should work great (more on that below).
Like Ber and Merlin, I find myself using the delta too. In template.php, I find myself doing this:
function phptemplate_get_block($block_id) { $block = block_block('view', $block_id); return $block['content']; }
Then in node/page.tpl.php I do:
<?php print phptemplate_get_block(6); ?>
Not pretty, and has hard coded block deltas, but it works.
The reason is, I don't want the block title to be displayed. I know that this can be handled with CSS, but prefer not to have it altogether.
So on my to do list, there is a task to make it an option to turn off the display of a block's title.
Now that block regions can be anywhere, they can be in all sorts of crazy places.
In such situations, the display of the title should be turned off for the region.
I forgot to say that this goes well with the regions and the theme. In template.php there would be: function mytheme_regions() { return array( 'ad_top' => t('ad top'), 'ad_links' => t('ad links'), 'ad_bottom' => t('ad bottom'), 'right' => t('right sidebar'), 'left' => t('left sidebar'), 'content' => t('content'), 'header' => t('header'), 'footer' => t('footer') ); } And then in node/page.tpl.php there would only be: <?php print $ad_top ?> And the placement would be via the admin/block interface. Nice and simple ...
Op maandag 15 mei 2006 17:09, schreef Khalid B:
I forgot to say that this goes well with the regions and the theme.
I love the route of regions! It allows me to build code without depending on Deltas and modulenames. Thanks for the tip! This was exactly what I was looking for. Bèr
Khalid B wrote:
On 5/15/06, Khalid B <kb@2bits.com> wrote:
On 5/15/06, Bèr Kessels <ber@webschuur.com> wrote:
Hello list,
One thing that has bothered me for a long time, is how to get/find/parse blocks in a simple way.
Problems are: * you need to read the code to find the "delta". Modules like views require you to hover the admin/blocks/edit links in order to find the delta. * a block returned by hook_block('view') needs casting and remodelling before I can be passed to theme_block.
I addressed the last point with a helper function get_block.
But that function still has the first problem above: You need to know a) the module that makes the block and b) the delta.
Does anyone know a trick for this? Or did I miss an API function? Is someone working on code for this?
NOTE: I am not particularly interested in a discussion to revise the core block architecture. Eventhough that might be an interesting project, I am looking for an intermediate function/api-set right now :)
Initially, I used flexiblock to get the blocks I wanted where I want them (e.g. adsense blocks),
Later, I decided that less dependancies is better, and to do it directly from core.
In 4.7, there is the block regions stuff, which should work great (more on that below).
Like Ber and Merlin, I find myself using the delta too. In template.php, I find myself doing this:
function phptemplate_get_block($block_id) { $block = block_block('view', $block_id); return $block['content']; }
Then in node/page.tpl.php I do:
<?php print phptemplate_get_block(6); ?>
Not pretty, and has hard coded block deltas, but it works.
The reason is, I don't want the block title to be displayed. I know that this can be handled with CSS, but prefer not to have it altogether.
So on my to do list, there is a task to make it an option to turn off the display of a block's title.
Now that block regions can be anywhere, they can be in all sorts of crazy places.
In such situations, the display of the title should be turned off for the region.
I forgot to say that this goes well with the regions and the theme.
In template.php there would be:
function mytheme_regions() { return array( 'ad_top' => t('ad top'), 'ad_links' => t('ad links'), 'ad_bottom' => t('ad bottom'), 'right' => t('right sidebar'), 'left' => t('left sidebar'), 'content' => t('content'), 'header' => t('header'), 'footer' => t('footer') ); }
And then in node/page.tpl.php there would only be:
<?php print $ad_top ?>
And the placement would be via the admin/block interface.
Nice and simple ... The one downside to this is that, at the moment, a block can only live in one region per theme unless I add the blocks to a particular region myself.
Op maandag 15 mei 2006 22:29, schreef Earl Miles:
The one downside to this is that, at the moment, a block can only live in one region per theme unless I add the blocks to a particular region myself.
This is a "bug" that has been reported numerous times. It is a bug that has kept me from releasing "sections module" for 4.7. Because it makes any themeswitching completely useless! IMNSHO this is such a serious bug that it could even be considered a 4.7.x fix, but I am not sure that will happen. :) I will be working on this somwhere on the road to the next release, but I might release a core-patch-only just to make sections module work again. Bèr
Perhaps I'm misunderstanding you, but I'm using sections.module CVS on a 4.7 site right now with no problems that couldn't be traced back to user error. :-) Perhaps I'm misunderstanding you. What doesn't work in sections.module? -- Larry Garfield On Mon, May 15, 2006 4:02 pm, Bèr Kessels said:
Op maandag 15 mei 2006 22:29, schreef Earl Miles:
The one downside to this is that, at the moment, a block can only live in one region per theme unless I add the blocks to a particular region myself.
This is a "bug" that has been reported numerous times. It is a bug that has kept me from releasing "sections module" for 4.7. Because it makes any themeswitching completely useless!
IMNSHO this is such a serious bug that it could even be considered a 4.7.x fix, but I am not sure that will happen. :)
I will be working on this somwhere on the road to the next release, but I might release a core-patch-only just to make sections module work again.
Bèr
Op maandag 15 mei 2006 23:53, schreef Larry Garfield:
What doesn't work in sections.module?
Having multiple templates (!=styles) requires you to configure the blocks correct for each and every template. Else one "section" will show certain blocks while others will not. And the way to configure blocks is to enable each theme one by one and to then configure the blocks for that theme. Even worse is that if you start using complex config like block-path settings youll have to make sure that config is carried across each block-theme combination. You can imagine that with 5 themes/sections and 12 blocks this is near to impossible. Youll need to sync 60 config options. Bèr
On Monday 15 May 2006 20:37, Bèr Kessels wrote:
Op maandag 15 mei 2006 23:53, schreef Larry Garfield:
What doesn't work in sections.module?
Having multiple templates (!=styles) requires you to configure the blocks correct for each and every template. Else one "section" will show certain blocks while others will not.
You can imagine that with 5 themes/sections and 12 blocks this is near to impossible. Youll need to sync 60 config options.
Bèr
Ah, OK, I see what you mean. It's not broken, just a bit clunky. :-) The larger issue is that there are two axes by which themes can change: page-author chosen or user-chosen. Right now, core favors user-chosen almost completely. sections.module is a step toward page-author chosen, but of course how those two interact is an open question. What does sections.module do, currently if a user has a custom theme chosen? Which wins? Which should win? I'm not really sure what the answer is for that question. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
Khalid B wrote:
Like Ber and Merlin, I find myself using the delta too. In template.php, I find myself doing this:
function phptemplate_get_block($block_id) { $block = block_block('view', $block_id); return $block['content']; }
Then in node/page.tpl.php I do:
<?php print phptemplate_get_block(6); ?>
Not pretty, and has hard coded block deltas, but it works.
I actually like this. As I get more into developing for Drupal on a professional level and less on a hobbyist level, I've come to realize that on this level, database dependencies for functionality can be bad. You can't easily but the database in version control; but you can put your template.php in version control. The fewer db dependencies you have, the easier it is to set up test sites for various purposes.
On 5/15/06, Earl Miles <merlin@logrus.com> wrote:
Khalid B wrote:
Like Ber and Merlin, I find myself using the delta too. In template.php, I find myself doing this:
function phptemplate_get_block($block_id) { $block = block_block('view', $block_id); return $block['content']; }
Then in node/page.tpl.php I do:
<?php print phptemplate_get_block(6); ?>
Not pretty, and has hard coded block deltas, but it works.
I actually like this.
But, 6 is not portable to other sites. In another site it maybe 1 or 22. So not sure what having it under version control would achieve. If it is: <?php print $region_adsense_top; ?> Or <?php print $region_announce; ?> It is less code, and more descriptive ...
As I get more into developing for Drupal on a professional level and less on a hobbyist level, I've come to realize that on this level, database dependencies for functionality can be bad. You can't easily but the database in version control; but you can put your template.php in version control. The fewer db dependencies you have, the easier it is to set up test sites for various purposes.
You can use mysqldump without the extended insert option, and put that under your favorite version control system. You may want to delete the rows from things like cache, accesslog, and watchdog before you do so. The site content is now versioned for you ... sort of ...
On 15 May 2006, at 6:47 PM, Khalid B wrote:
You can use mysqldump without the extended insert option, and put that under your favorite version control system. You may want to delete the rows from things like cache, accesslog, and watchdog before you do so.
Or put settings like that in a site specific .install (even if it's a dummy module) -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Khalid B wrote:
On 5/15/06, Earl Miles <merlin@logrus.com> wrote:
But, 6 is not portable to other sites. In another site it maybe 1 or 22. So not sure what having it under version control would achieve.
If it is: <?php print $region_adsense_top; ?> Or <?php print $region_announce; ?>
It is less code, and more descriptive ... Not all blocks just use numbers as their deltas; and I've taken to naming my deltas so that when more blocks are added, it's more obvious what's going on. It'd be nice of Drupal moved toward using descriptive deltas rather than simply numbers. You can use mysqldump without the extended insert option, and put that under your favorite version control system. You may want to delete the rows from things like cache, accesslog, and watchdog before you do so. And, in fact, this is exactly what I do, but for some things it's highly inconvenient.
On 5/15/06, Earl Miles <merlin@logrus.com> wrote:
Khalid B wrote:
On 5/15/06, Earl Miles <merlin@logrus.com> wrote:
But, 6 is not portable to other sites. In another site it maybe 1 or 22. So not sure what having it under version control would achieve.
If it is: <?php print $region_adsense_top; ?> Or <?php print $region_announce; ?>
It is less code, and more descriptive ...
Not all blocks just use numbers as their deltas; and I've taken to naming my deltas so that when more blocks are added, it's more obvious what's going on. It'd be nice of Drupal moved toward using descriptive deltas rather than simply numbers.
I think that regions solve a major part of that. It was cool when I added the regions I have to template.php, and the print $region_id in the page.tpl.php, and saw the yellow markers in the admin/block screen ... Think of deltas as the lowest level (block identifiers). On top of that there are region identifiers. Each region can have one or more blocks in it. It makes the block delta insignificant. You can have a region with just one block in it, and do what you wanted to do with the delta. regionB -> b1 + b7 + b47 regionX -> b88 + b2 If you decide later that b7 should be in regionX it is just a simple admin/block change of assigning regionX to b7. That is it. No code changes or theme changes. (Not sure if that relates to your versioning thing, but it is a very nice and useful concept regardless).
Not all blocks just use numbers as their deltas; and I've taken to naming my deltas so that when more blocks are added, it's more obvious what's going on. It'd be nice of Drupal moved toward using descriptive deltas rather than simply numbers. Very true. One of the most disturbing things when styling a theme is to workout the delta's. Very inconvenient. Probably the main reason why you won't see a lot of 'special' treatment for blocks.
The only cons of this would be with autogenerated blocks. And probably slightly increased memory usage, but that is simply squeezing the cons dry. Anyway, deltas are a misnomer as many other things.
On 15 May 2006, at 17:39, Earl Miles wrote:
Like Ber and Merlin, I find myself using the delta too. In template.php, I find myself doing this:
function phptemplate_get_block($block_id) { $block = block_block('view', $block_id); return $block['content']; }
Then in node/page.tpl.php I do:
<?php print phptemplate_get_block(6); ?>
Not pretty, and has hard coded block deltas, but it works.
I actually like this. As I get more into developing for Drupal on a professional level and less on a hobbyist level, I've come to realize that on this level, database dependencies for functionality can be bad. You can't easily but the database in version control; but you can put your template.php in version control. The fewer db dependencies you have, the easier it is to set up test sites for various purposes.
We could change numeric IDs by labels? -- Dries Buytaert :: http://www.buytaert.net/
Op dinsdag 16 mei 2006 10:09, schreef Dries Buytaert:
We could change numeric IDs by labels?
Yes. And we don't even need a patch for that. The only thing that breaks is labels with odd charsets and spaces (breaks the HTML Ids). Its only a change needed in the docs and guidelines. Bèr
Bèr Kessels wrote:
* you need to read the code to find the "delta". Modules like views require you to hover the admin/blocks/edit links in order to find the delta.
Deltas are generally numeric, but are stored as a (probably relatiovely short) varchar. So there is no reason why they have to be numeric, in my module coding I always use strings. To remove deltas and make themers happy just need to rename them all in HEAD and figure out a DB update so the block settings don't get clobbered. -- Neil Drumm http://delocalizedham.com/
participants (8)
-
Adrian Rossouw -
Bèr Kessels -
Dries Buytaert -
drupal -
Earl Miles -
Khalid B -
Larry Garfield -
Neil Drumm