Is there a best practice for including an html file containing image source tags directly in the page.tpl.php file or is that typically frowned upon? I'm trying to embed a custom navigation banner at the top of my theme and haven't found any modules or blocks that would allow me to accomplish this. Some expert advice would be much appreciated.

Thanks!

Comments

naveenpl’s picture

You can use an existing theme and modify it.
On page.tpl.php you can create a div or a table in which your menu goes.
Class for them can be defined at style.css in that folder.
Images can be passed through theme function or can be directly coded in page.tpl.php file.

Hope this will help
Cheers.

samwich’s picture

I am looking into adding static images to my page.tpl.php document, and I am confused as to where this page looks for images. I tried just

			<div id="logo-mission">
                	<dl>
                        <dt id="about"><a href="localhost/drupal-5.7/about"><img src="images/recent_projects.jpg" height="26" border="0"/></a></dt>
                        </dl>
                        </div>

but it would not display the images. I am using a modified zen theme, on drupal 5.7. Where should the images go, and how should the path be defined, so that I can add static images onto my drupal template?

-Thanks

BladeRider’s picture

Let's say your theme lives in sites/all/themes/my-cool_theme, and you have a subdirectory images in there to hold your static images. Now say you have a file called banner.jpg in this subdirectory, the path so far would look like:

 sites/all/themes/my-cool_theme/images/banner.jpg

To get Drupal to find this, we need to add some PHP that calls a Drupal function and builds the image path up..

Here's a fragment of code that could be pasted into your page.tpl.php (with the theme, subdir & filename changed to your own):

<?php
  // Create a variable to hold the full path, in our theme, to the image.
  //   path_to_theme() takes care of creating the correct path for the active theme (which is likely your own custom one)
  $my_static_banner = path_to_theme() . '/images/banner.jpg';
?>

<img src="<?php print $my_static_banner ?>" />

As you can see, a second fragment of PHP inside the <IMG> tag outputs the path. Also note how we don't provide any path details to the top-level of the theme, just any sub-dirs - the path_to_theme() takes care of that.

samwich’s picture

Thanks, I got to try it out this morning, and it worked just like I wanted.

-Sam

samwich’s picture

I did

			<div id="logo-mission">
<?php
  // Create a variable to hold the full path, in our theme, to the image.
  //   path_to_theme() takes care of creating the correct path for the active theme (which is likely your own custom one)
  $my_static_contact = path_to_theme() . '/images/contact_us.jpg';
  // Create a variable to hold the full path, in our theme, to the image.
  //   path_to_theme() takes care of creating the correct path for the active theme (which is likely your own custom one)
  $my_static_request = path_to_theme() . '/images/request.jpg';
?>
               	<dl>
            
                        <dt id="contact"><a href="localhost/drupal-5.7/about"><img src="<?php print $my_static_contact ?>" height="27" border="0"/></a></dt>
                        <dt id="request"><a href="localhost/drupal-5.7/request"><img src="<?php print $my_static_request ?>" height="27" border="0"/></a></dt>
                </dl>
            </div>

and that works fine for the front page, forum page, blog page, etc. But the directory breaks on any of the node pages. If I look for the image path on the front page I see,
http://localhost/drupal-5.7/themes/zen/images/contact_us.jpg
But on the node pages the image path becomes,
http://localhost/drupal-5.7/node/themes/zen/images/contact_us.jpg

I am running drupal 5.7 with a modified zen theme. And my images are located in htdocs\drupal-5.7\themes\zen\images. The code I posted previously is in
drupal-5.7\themes\zen\page.tpl.php

Any help would be appreciated.

samwich’s picture

Does anyone know how to use a php variable to always get to sites/all/themes/...

the path_to_theme works on page.tpl.php but it does not work on page-front.tpl.php or any other templates.

For example on the front page, the image path changes to drupal-6.2/front/sites/all/themes/...
when I use the path_to_theme to create a variable.

Anyone?

davemybes’s picture

Try using the $directory variable.
______________________________________________________________________________________________________
mybesinformatik.com - Drupal website development

______________________________________________________________________________________________________

nehalmehta’s picture

<img src ="<?php print base_path().path_to_theme(); ?>/images/XXX.jpg" />

kesmeby’s picture

I'm not sure why this didn't attach to your message the first time. But I wanted to let people know that your solution works.

cfl_techy’s picture

it didn't seem to work for me...
i did exactly the same thing...
i also tried to hardcoding the path, but no luck :(

any thoughts would be appreciated...

thanks in advance

kesmeby’s picture

Worked like a charm.

monkeybelly’s picture

Thanks for this post and answers. I've been scratching my head at this one all day.