<?php
# Задаем данные:
$title = 'Название.';
$keywords = 'Ключевые слова.';
$description = 'Описание.';
$category = 'Категория.';
$posts = 'Сообщение.';
$foo = 'Привет.';
# Формируем текущую страницу:
$tpl = file_get_contents('./main.tpl');
$tpl = str_replace('{title}', $title, $tpl);
$tpl = str_replace('{keywords}', $keywords, $tpl);
$tpl = str_replace('{description}', $description, $tpl);
$tpl = str_replace('{category}', $category, $tpl);
$tpl = str_replace('{posts}', $posts, $tpl);
$tpl = str_replace('{foo}', $foo, $tpl);
# Выводим текущую страницу:
echo $tpl;
?>
А это строки файла шаблона main.tpl
<html>
<head>
<title>{title}</title>
<meta name="keywords" content="{keywords}"/>
<meta name="description" content="{description}"/>
</head>
<body>
<table>
<tr>
<td>
{posts}
</td>
<td>
{category}
</td>
<td>
{foo}
</td>
</tr>
</table>
</body>
</html>
При выполнении все выводится корректно.
Если же я попытаюсь изменить код и вставить php непосредственно в шаблон:
Файл index.php:
<?php
# Задаем данные:
$title = 'Название.';
$keywords = 'Ключевые слова.';
$description = 'Описание.';
$category = 'Категория.';
$posts = 'Сообщение.';
# Формируем текущую страницу:
$tpl = file_get_contents('./main.tpl');
$tpl = str_replace('{title}', $title, $tpl);
$tpl = str_replace('{keywords}', $keywords, $tpl);
$tpl = str_replace('{description}', $description, $tpl);
$tpl = str_replace('{category}', $category, $tpl);
$tpl = str_replace('{posts}', $posts, $tpl);
# Выводим текущую страницу:
echo $tpl;
?>
Вот строки файла шаблона main.tpl
<html>
<head>
<title>{title}</title>
<meta name="keywords" content="{keywords}"/>
<meta name="description" content="{description}"/>
</head>
<body>
<table>
<tr>
<td>
{posts}
</td>
<td>
{category}
</td>
<td>
<?php
echo "Привет мир!";
?>
</td>
</tr>
</table>
</body>
</html>
То получаю ошибку:
[an error occurred while processing this directive] The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script. [an error occurred while processing this directive]
Есть ли возможность вставить php в шаблон?