By AngelicLight on
Hi, there,
I'm looking to style block titles in unique ways to each block. Do blocks allow HTML for titles?
Thanks a lot,
- Paul
Hi, there,
I'm looking to style block titles in unique ways to each block. Do blocks allow HTML for titles?
Thanks a lot,
- Paul
Comments
No, but you could do
No, but you could do additional stying in the block.tpl.php file, and in the CSS for the theme.
This is a snippet from a block.tpl.php file (taken from Fusion Core theme)
That's where you add additional html to the block's title. If you added other classes/ids, these could then be styled with CSS
Thanks so much! I wanted the
Thanks so much!
I wanted the block titles to be an image, or at least allow for unique styling per block title, within the title verbiage itself.
I guess this isn't possible, then?
You have options still. Take
You have options still.
Take in a look in your html source and, depending on the theme you're using, you'll have
<div>senclosing each block that probably have unique ids. So you style these with css like so (for example):Or you could hide the text and place an image into your block (onmly really appropriate for custom blocks, not those generated by other modules):
Or you could hide the text and display a background image instead:
Or you build some logic into the block.tpl.php file, or even build a module to associate block titles with images.
CCK Imagefield and Views
OR you could upload the images you want to use as a title via Imagefield. Then in Views you could display them at the top of the node and choose NOT to display the tile. You could even write a bit of PHP that only prints the text version of the title if there is no image.
EDIT: I see you are talking about BLOCK headers, not node titles. My mistake. Carry on.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
An option that should work nicely for you
I have created a workaround that I documented here.
http://blog.marceisaacson.com
Thank you!
Thank you!
Use $block->delta to target specific block.
You can add an if or switch statement at the top of block.tpl.php to match the unique block delta and then you can change the value of the
$block->subject:Install devel and the use
kpr($block->delta);to find out what the delta is.Don't forget to pass the title through the t function.
I'm having a similar
I'm having a similar issue--though it's not images--I know how to use CSS to pull that off. In this case, part of the text in the block needs to be styled different from the rest of the text in the block. In this case, they want one particular word to be a different color--and alas it's not the first word, so the :first pseudo-selector won't help. But another client wanted to italicize a foreign word, and I had to just say they couldn't. Is there any module or theme fix that will allow even the Filtered HTML subset of tags into the Block Title?
Yes, you can, with a little bit of "hacking" in template.php
You can modify your block's title with a little bit of ugly "hack" in your theme's
template.phpfile (which is located in'http://<yoursite>/sites/all/themes/<YOURTHEMEPATH>/template.php').The following will just be an example of my case, but you can "convert" it to your own needs...
For example, I wanted to change the title of my Ubercart AJAX Cart block for an HTML image with a shopping cart icon, because it looks nicer than a "Shopping Cart" (or similar) text.
In my case, I set the following block title in the block's configuration page (e.g.
http://<yoursite>/admin/build/block/configure/uc_ajax_cart/0): "AJAX Shopping Cart" (without the quotes).I wanted to keep some of the original block title's elements, because the module and Drupal put a wrapper (with a link [
<a>] to let the cart toggled) around it, so I had to search for my title ("AJAX Shopping Cart") with a regular expression, and modify that to a new one.Not too nice, but solves the problem.
I opened my theme's
template.phpwith an editor, and put the following in it (usingtheme_preprocess_block()):And it works.
Ask if you didn't succeed in changing your own title based on this example.
This is awesome. Thank you.
This is awesome.
Thank you. :)
When you're ready to set the
When you're ready to set the block title, $vars['title'] doesn't work for me in Drupal 7 - instead I use $vars['block']->subject
Style the content as a title
Why not just set the block title as blank and style an element in the block's body content (in full or partial html mode) to look like a title?
FULL HTML IN BLOCK TITLE
I think that's the best idea.
I need to have anchor ID in each block so that user could scroll to the exact block after clicking on the menu link which is at the beginning of the page.
If I hack the block tpl file, than every block would have the same anchor and it would become static.
I don't need that, blocks must have individual anchors, it must be dynamic.
Use $block->delta to target specific block.
You can add an if or switch statement at the top of block.tpl.php to match the unique block delta and then you can change the value of the
$block->subject:Install devel and the use
kpr($block->delta);to find out what the delta is.Don't forget to pass the title through the t function.
(Solved) Block Class Styles
One of the features of Block Class Styles is to allow to have HTML in block titles. I know this is an old thread, but I think it is important to add a solved for future references.