Any idea how to do this? I have a background image that propagates the entire site, but I want one on the homepage that is exclusive to only the homepage. thanks!


Shabana Blackborder’s picture

You can add the background image to page--front.tpl.php in your theme and it will only apply to the front page.

Shabana Navas
Drupal Developer

nikkwong’s picture

Hi, thanks, so the code would be on that page,

<body <?php body_class();

and then I just create any class and then define that class in CSS? Thanks so much!

vietdrupal’s picture

There is 2 solutions:
1. define page--font.tpl.php
In the template, define a wrapper element
<div id="home-page">

Note: in this template not include <body> tag

2. define html--font.tpl.php

You can copy this template from /modules/system/html.tpl.php

In this template include <body> tag
<body class="body-home">

Remember tho clear cache every time you override template.

Then you can define css for "body-home" or "home-page" in your css file.

nikkwong’s picture

I am sorry--this makes no sense to me..can you elaborate in simpler terms? Thanks!

vietdrupal’s picture

In drupal7, you can define template for every page. For more example with your theme is "hellotheme".
1. If you want to define the template for your home page with show different with other page. You can create file name hellotheme/templates/page--front.tpl.php

In this file you can put more HTML code.
Note that: in this file not include tags <body>. So to show a different background, you should wrap your html element with parent '<div>';

2. Another way if you don't want to wrapper your content with '<div>', you must define (exactly override the HTML) by create file hellotheme/templates/html--front.tpl.php.

In this file you can put more css to tag <body class="..."> that make your home page different with others.

Then the remain things is define css in your css file.

nikkwong’s picture

worked great. thanks!

WorldFallz’s picture

Why not just do it with CSS? Most themes add a class to the body tag of the front page.

Care about the future of the forums? Please join our conversation and show support for improving the forums infrastructure.

Shabana Blackborder’s picture

Yeah, now that I think of it, that seems the easiest way.

Shabana Navas
Drupal Developer