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
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
...
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; }
Professional Drupal Design and Theme Services
Thanks
Thanks jmburnz. That fixed the problem.
what do u mean by "..PHP
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
...
In this first example notice how the HTML is embedded within the PHP print statement:
<?phpif ($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:)
Professional Drupal Design and Theme Services
Did you try using Block theme
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
Chetan Jain
http://www.cjain.com