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

WorldFallz’s picture

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

opendevel’s picture

Ok, but I would like to be able to write HTML code in the block's title field. Can I do it?

WorldFallz’s picture

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

opendevel’s picture

How should I modify it?

WorldFallz’s picture

Basically, however you want.

For example, I use zen as the basis for most of my themes. The block.tpl.php file is:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="block block-<?php print $block->module ?>">  
  <div class="blockinner">
    <h2 class="title"> <?php print $block->subject; ?> </h2>
    <div class="content">
      <?php print $block->content; ?>
    </div>    
  </div>
</div>

If I wanted to add an image before the title I could change it to:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="block block-<?php print $block->module ?>">  
  <div class="blockinner">
    <img src="/images/block_image.png" alt="" width="33" height="32" />
    <h2 class="title"> <?php print $block->subject; ?> </h2>
    <div class="content">
      <?php print $block->content; ?>
    </div>    
  </div>
</div>

===
"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

blackwidowdc’s picture

Would this code Only local images are allowed. 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!

muratkolukirik’s picture

How can I show h2 block behind an image on Drupal 7

kevinquillen’s picture

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

dinaiz’s picture

... you can have a look at http://drupal.org/node/44702

greg.harvey’s picture

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!

vegantriathlete’s picture

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.

mcfilms’s picture

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