Reputation: 81711
I want to change the title of my PHP pages dynamically but since the headers and footer sections are include files so I cannot use <title><?php echo $title;?></title>
kind of solution.
I am wondering if there is any solution such as the one in Asp.NET Page.Title = "Some Title";
maybe like $page->set_title('Programmers Palace');
Many thanks...
Upvotes: 2
Views: 101
Reputation:
<?php
$title = 'My Page';
include 'header.php';
then in header.php:
<title><?php echo $title;?></title>
This works because file includes in php are treated as if they are "pasted in between there".
Upvotes: 1
Reputation: 490153
Since the headers and footer sections are include files so I cannot use
<title><?php echo $title;?></title>
kind of solution.
You can. Just because the files are included doesn't mean you can't echo things there.
If you had a Page
object...
<?php
$page = new Page('Programmers\' Palace');
include 'includes/header.php';
<head>
<title><?php echo $page->getTitle(); ?></title>
</head>
Upvotes: 5