On 1/30/2011 12:36 PM, Michael Bishop wrote:
Is there a way to pass a block specific class?
For instance, the Twitter block uses an unordered list that doesn't
have a class or ID, so there's no way to target the list to style it.
One option would be to update the block.twitter.php file with a class
or ID, but it would be better IMO to be able to pass a class in
addition to first/last to that block area.
I made some changes to the block class so that it's easier to target the
output with CSS and easier to output the correct CSS from the theme.
In themes, blocks should have a wrapper class defined, and it should
output $block->css_classes (always a string with space-delimited CSS
class names). This does several things.
The first thing it does is replace the multiple if() statements that
would normally trigger the output of the "first", "last", and "index_X"
classes with a single property that is output. That this is handy
should be obvious.
To this, I've added a new class "block-type-X" where X is the slugified
type name of the block. So if the block type is "twitter", then a class
of "block-type-twitter" is automatically added to the classes that are
output in the wrapper for $block->css_classes.
Another thing this does is it allows custom classes to be stored with
the block for output. The value of css_classes can be set as block data
which is stored in the database. If you create a field as part of your
block config form that stores a value for css_classes, then this value
will be an additional class output for that block.
Finally, there is now a filter hook for filter_block_classes($classes,
$block) that allows plugins and themes to alter the classes that are
assigned to the block for output. $classes is an array in this case,
and individual elements can be added or removed as needed. The values
of $block->_first, $block->_last, $block->_area, et al remain unaltered,
which may be useful.
Hope that's helpful.
Owen
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at http://groups.google.com/group/habari-dev