Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

page titles with php and tpl files

Status
Not open for further replies.

coily

Technical User
Jan 26, 2005
25
GB
Hi

I am a newbie to php and need some advice.

I'am developing a site that uses tpl files for the header, body and footer. This is then built using php includes.

The problem i have is that the header contains the html <title> but i want the body title added to this so the browser would display both as the title.

I think it is something along the lines of creating a variable called lets say SITE_TITLE for the header and PAGE_TITLE for the body then add the two together in the <title> tag.

Could someone put me straight on the syntax pleeeeaase!

I do hope my question makes sense, please be frank i can take it.

Thanks
 
I have never heard of a body title to be honest.
I have searched the web but cant find this.

So what is it you wish to accomplish?

JR
As a wise man once said: To build the house you need the stone.
Back to the Basics!
 
Hi

Sorry i wrote the previous post after to long looking at the same thing. Let me explain my self better.

I have a php web page which includes three files 1. A header file 2. An *_body file and 3. A Footer file these are html templates saved with the ext .tpl.

The header and footer are included on all pages where as the *_body changes depending on the page i.e index, about ect....

My problem is that the Header file contains the <title> tag and therefore all my pages will display that title(not what i want).

I think i need to create a variable for 'title' in the php file and parse it to the Header template. This way i can each page can have its own title.

If there is an easier way to do this i can't find it.

Thanks for the replys
 
parsing would work.

or if you are not averse to a wee bit of javascript you could try the following:

add an onload event to the <body> tag that looks like the following:
onload="javascript: document.title = document.title + ' New Document Title';"

 
before the header include create a variable, say $title and set it to your title text, then in the header include use <title><?$title?></title>

javascript will be of no use for search engine and many accessibility user agents.

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
Nightclub counting systems

So long, and thanks for all the fish.
 
agreed on the search engine and accessibility comment.

wouldn't the php syntax be either
<? echo $title; ?> or
<?=$title?> ?

I've never tried without the equals sign or the full php construct.
 
I had given up hope of getting an answer to this.

Thankyou both for your comments, the parsing of the variable $title worked with the syntax:

<?echo$title?>

The project is a social care site so javascript is out for the reasons stated.

Once again thanks

 
$page_title = "title"
include('header.tpl');
include('body.tpl');
include('footer.tpl');

In the header you write:
<title><?php echo $page_title; ?></title>

staffa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top