Reputation: 979
When I create dynamic titles for codeigniter header, it works ok, but when there is no any title passed from controller to view, it does not show default title, it shows "Undefined variable: title". Could you please check my code below and help me to find my mistake.
controller:
function index()
{
$data['title'] = "Dynamic Title";
$this->load->view('header', $data);
$this->load->view('layouts/home');
$this->load->view('footer');
}
view:
<title>
<?php if ($title)
{
echo $title;
}
else
{
echo 'Default Title';
}
?>
</title>
Upvotes: 0
Views: 531
Reputation: 316
<title>
<?php if (!empty($title))
{
echo $title;
}
else
{
echo 'Default Title';
}
?>
Upvotes: 1