Drupal Tips and Tricks: Using Blocks as Mini Stylesheets
This is a brief post about something that I have found useful in some instances, although some people would probably say that it isn't the most accepted or "kosher" way to style a Drupal site. But there are times when "useful" is important.
If you've been around Drupal for more than a few seconds, you either have already noticed or will soon notice that there is almost always (if not always) more than one way to do things. That might even be what some of us love about Drupal.
Blocks in Drupal don't always have to be used for visible content. As one example, I have found that they were quite well to do a little bit of CSS work on a particular page. Let's say you need to change the styling on one particular page, and the particular tags that you are going to modify are very general ones - probably classes like "content", "node", "tabs", etc.
Not all of the pages output by Drupal will always provide you with specific divs and classes to let you easily modify one particular page with CSS, without destroying other pages. So you could dig into modules and core files to force more specific output, or you could put together a custom TPL file and play around with PHP - just a few examples.
But if the specific task at hand doesn't call for this much effort, blocks can be used quite nicely for page specific styling - I'll just say mini-stylsheets. To do it this way, you can create a block, set the input type to PHP, and put your CSS in between some style tags. Then set the block to be displayed on the specific page in question, and viola, you have a mini-stylesheet.
For a quick demonstration, you can take a look at the various User page on Hope to Action -the create account, login, forgot password pages. A few quick blocks serving as mini-stylesheets were used to get rid of the typical tabs that appear under "/user" on a Drupal site as well as the rather generic "User Account" label. Again, this certainly wasn't the only way to accomplish this, but it was a quick way.
If you've been around Drupal for more than a few seconds, you either have already noticed or will soon notice that there is almost always (if not always) more than one way to do things. That might even be what some of us love about Drupal.
Blocks in Drupal don't always have to be used for visible content. As one example, I have found that they were quite well to do a little bit of CSS work on a particular page. Let's say you need to change the styling on one particular page, and the particular tags that you are going to modify are very general ones - probably classes like "content", "node", "tabs", etc.
Not all of the pages output by Drupal will always provide you with specific divs and classes to let you easily modify one particular page with CSS, without destroying other pages. So you could dig into modules and core files to force more specific output, or you could put together a custom TPL file and play around with PHP - just a few examples.
But if the specific task at hand doesn't call for this much effort, blocks can be used quite nicely for page specific styling - I'll just say mini-stylsheets. To do it this way, you can create a block, set the input type to PHP, and put your CSS in between some style tags. Then set the block to be displayed on the specific page in question, and viola, you have a mini-stylesheet.
For a quick demonstration, you can take a look at the various User page on Hope to Action -the create account, login, forgot password pages. A few quick blocks serving as mini-stylesheets were used to get rid of the typical tabs that appear under "/user" on a Drupal site as well as the rather generic "User Account" label. Again, this certainly wasn't the only way to accomplish this, but it was a quick way.


Post new comment