I'm working on some theme stuff, and wanted to know if it's possible to test for the condition if Right or Left menu blocks exist to be rendered. Basically, just want to check if any blocks are active, and set to be on the Left or Right side. I searched the site, but didn't easily come up with anything I plugged in. I've been pouring through other themes, for an example, but again didn't find anything.
I also check the Drupal Documentation, but was unable to locate anything. I suppose I could implement an SQL query through the tablespace, but that'd be pretty ugly to do. Is there a cleaner method of determining whether there are any Left or Right blocks that need to be rendered?
TIA.
-Shane
Comments
I figured the SQL syntax - still wondering about a better way
I figured the SQL syntax is basically:
Then simply compare if $right_result or $left_result is greater than zero. If so, then we've got a left/right set to render.
But - still would love a cleaner way - so I'm not imposing a DB Query overhead for each and every single page load for this silly a need...
-Shane
theme_blocks
I'm afraid it is not cleaner but you could call
theme_blocks("left")
and capture the data using output buffering. If you captured some data, you know there is at least one block to display.I guess the clean solution is to make
theme_blocks()
return it blocks in an associative array with (title, content)-tuples; if the array is empty there are no blocks. In your theme, you can then use this array to render each block.(Update: just return an array of block objects.)
Feel free to think this through a little and to work up a patch.
just submitted a patch to the ml
that does this better
I ultimately ended up doing t
I ultimately ended up doing this:
COLS sets my table TD fields to either 2 or 3. If 2, main content TD gets 80%, while if 3 COLS (eg left/right and content) then the main content TD is only 60% wide.
Then I test my "$left_results" and "$right_results" to determine if I should actually build the TD sections either in the header for the left columns, or the TD sections in the footer for the right columns.
The net effect is right. Basically if anything is set to left or right under Blocks admin - then it auto-magically builds the container table and does it all correctly.
I'll look forward to the "better" way of doing it in future releases.
-Shane
i implemented this already .. differently though
this is mostly due to how phptal (the template engine for the theme i am working on) does it's assignments .. so it generally wouldnt work for other things that echo right now.