Reputation: 53
I am using these codes so that I can pass the file needed or other attribute through variables but it is not working properly. I don't know what the problem is because the code looks pretty fine to me. Index page does not show any content from header's page.
helper.php
<?php
function render($template, $data = array())
{
$path = $template . ' .$php ';
if(file_exists($path))
{
extract($data);
require($path);
}
}
header.php
<?php require_once('helper.php') ?>
<!doctype html>
<head>
<title><?php echo htmlspecialchars($title); ?></title>
</head>
<body>
Index.php
<?php
require_once('helper.php');
render('header', array('title' => 'Index'));
?>
Upvotes: 0
Views: 53
Reputation: 7884
I believe you must want this line
$path = $template . ' .$php ';
to actually be this:
$path = $template . '.php';
Upvotes: 0
Reputation: 91734
This is wrong:
$path = $template . ' .$php ';
You are adding spaces and a $
sign to your path:
$path = $template . '.php';
Upvotes: 1