Drupify Theme - How do I add background image to block titles

vsr - April 1, 2009 - 04:57

I created a block template with this code.

<?php if ($block->subject): ?>
  <div class="orangebar"><h2><?php print $block->subject ?></h2></div>
<?php endif;?>

  <div class="content"><?php print $block->content ?></div>
</div>

I created a CSS class

div.orangebar { background url(images/orangebar.png) 0 0 no-repeat; width: 100%; }

In the page code, I see the following, but the orange bar does not show.
  <div class="orangebar"><h2>User-1</h2></div>

Can somebody please tell me what I am doing wrong. Thanks in advance your help.

not sure if the syntax u used

mm167 - April 1, 2009 - 05:21

not sure if the syntax u used are wrong, but i will try ..

<?php

if ($block->subject) {
   print
'<div class="orangebar"><h2>' . $block->subject . '</h2></div>';
}

?>


and (remove div)

.orangebar { background url(images/orangebar.png) 0 0 no-repeat; width: 100%; }

We go the drupal way. How about you?
http://www.drupalway.com

...

Jeff Burnz - April 1, 2009 - 22:29

The above comment is actually not what to do, ideally PHP should be in HTML not the other way around.

The problem is not your PHP, its your CSS, you are missing a colon (:) after background.

div.orangebar { background : url(images/orangebar.png) 0 0 no-repeat; }

Thanks

vsr - April 2, 2009 - 02:28

Thanks jmburnz. That fixed the problem.

what do u mean by "..PHP

mm167 - April 2, 2009 - 03:46

what do u mean by "..PHP should be in HTML .."?

yes..i overlooked the ":"

We go the drupal way. How about you?
http://www.drupalway.com

...

Jeff Burnz - April 2, 2009 - 08:44

In this first example notice how the HTML is embedded within the PHP print statement:

<?php
if ($block->subject) { print '<h2>' . $block->subject . '</h2>'; }
?>

Ideally you should avoid that in tpl files and write your PHP inside of the HTML, i.e.:

<?php if ($block->subject): ?>
  <h2><?php print $block->subject ?></h2>
<?php endif; ?>

Notice how there is no HTML embedded within the PHP code, they are kept separate.

I generally believe that this is a Drupal convention although you are of course free to do what you want:)

Did you try using Block theme

jainrutgers - April 2, 2009 - 16:36

Did you try using Block theme module....as the name suggest you can theme any block as you want. Its really nice even i used it.

chetan

 
 

Drupal is a registered trademark of Dries Buytaert.