Page 1 of 1

How to change an image based on the page title

Posted: Wed Dec 16, 2009 4:15 am
by wmatos
Hello,

Hopefully someone will be able to give me a hand. I'm developing my first theme for drupal and got stuck trying to add some php to dynamically change an image in a div according to the page's title. Drupal by default will create a variable called $title which is a string with the page's title. So I want to check: If $title is title1, use image1_png. The code I've created is:

Code: Select all

 
<?php 
  $title = "title1";
  $gd_image = "images/side_gd.png";
  if ($title == "title1") {
    <img src="<?php echo htmlspecialchars($gd_image); ?>"/>
  else { <img src="image/other.png"/>
  }
?>
 
Can someone tell me what am I doing wrong? I'm very new to php and can't see to work out...
Thanks in advance!

Re: How to change an image based on the page title

Posted: Wed Dec 16, 2009 4:39 am
by daedalus__
what is the function htmlspecialentities() for? did you check the output?

the easiest way is to put the title in a variable, output the variable inside the title tag then use the same variable as the filename of the image or something.