Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By opendevel on
Hello,
How can I enable inserting HTML code into the block title, so I would be able to insert an image and CSS in it?
I would be extremely grateful for your help.
Comments
Blocks have css classes and
Blocks have css classes and ids-- you should be able to add images to your blocks in almost any combination purely with css in your theme's style.css file.
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Ok, but I would like to be
Ok, but I would like to be able to write HTML code in the block's title field. Can I do it?
You should be able to do
You should be able to do that by modifying the block.tpl.php file in your chosen theme.
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
How should I modify it?
How should I modify it?
Basically, however you want.
Basically, however you want.
For example, I use zen as the basis for most of my themes. The block.tpl.php file is:
If I wanted to add an image before the title I could change it to:
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Still Learning
Would this code only pull a file titled block_image? I am trying to understand this as I want create different images for each block title.
Would I use "$block->subject.png" to accomplish this? Thanks!
Drupal 7
How can I show h2 block behind an image on Drupal 7
If you get the Block Class
If you get the Block Class module, all you would add to block.tpl.php is the print $blockClass statement inside the div class, which is probably easiest.
===========
read my thoughts
Alternatively.....
... you can have a look at http://drupal.org/node/44702
There *should* be a module for this
Many people have clients who want to manage their own graphical block titles and are not developers, often have *no* HTML/CSS experience whatsoever. There should be an equivalent to the Image Title module for blocks:
http://drupal.org/project/image_title
In fact, if we get to take over Image Title then I will add this as a feature - I need it too often!
--
https://www.codeenigma.com/
Possible idea for how the module could work
I described a quick work around that could be expanded into a module here. But, there are serious security risks from allowing unfiltered HTML in the title. So, I would need to give a lot more thought to how I would code a complete module.
http://blog.marceisaacson.com
I think....
Most developers use Views for this. So the input form still requires a text title, but there is also a field to upload a title graphic. The magic of doing it this way is you can instantly check (and resize) the graphic as needed. You can also include markup so the text title is the ALT tag for the graphic. There can be a bit of php to use the text headline if no graphic is present.
Really, I think if you try it with Views you will really like it. You know what they say: "Once you try Views, You'll never wear shoes." Or something like that.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com