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.

Comments

mm167’s picture

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%; }

Jeff Burnz’s picture

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; }

vsr’s picture

Thanks jmburnz. That fixed the problem.

mm167’s picture

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

yes..i overlooked the ":"

Jeff Burnz’s picture

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

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:)

jainrutgers’s picture

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