Я создал свой простой шаблон для php-сайта. проблема в том, что я не знаю, как включить мои файлы css и javascript.
вот мой файл index.php
<?php
include'core/template.php';
$temp=new Template();
$settings=array("title","page_title","welcome_word");
$values=array("RIS - Home","Results Information System","Welcome to result
Information system");
$temp->header($settings,$values);
$temp->footer();
?>
вот мой файл template.php
<?php
class Template {
public function header($setting,$values){
$file=file_get_contents("http://localhost/RIS/src/header.php");
$count=0;
foreach ($setting as $setting) {
$file=str_replace('{'.$setting.'}',$values[$count],$file);
$count++;
}
echo $file;
}
public function footer(){
$file=file_get_contents("http://localhost/RIS/src/footer.php");
echo $file;
}
}
?>
вот мой файл header.php
<!DOCTYPE html>
<html>
<head>
<title>{title}</title>
</head>
<body>
<header>
<h1>{page_title}</h1>
{welcome_word}
</header>
My contents goes here...
вот мой файл footer.php
<footer>
Copyright © RIS 2013.
</footer>
</body>
</html>
У меня есть файлы css и js файлы в папке с ресурсами, так как я могу включить их в свой шаблон?
Я бы использовал выходные буферы & include вместо file_get_contents, include'core/template.php';
вот пробел отсутствует.
В вашем случае, почему бы просто не поместить CSS и JS в header.php
?
Или, если вы хотите неблокировать, поместите CSS в header.php и JS в footer.php
Для файлов CSS:
<!DOCTYPE html>
<html>
<head>
<title>{title}</title>
<link rel="stylesheet" href="path/to/assets/yourcss.css" type="text/css">
</head>
<body>
<header>
<h1>{page_title}</h1>
{welcome_word}
</header>
My contents goes here...
и для javascripts:
<footer>
Copyright © RIS 2013.
</footer>
<script src="path/to/assets/yourjs.js"></script>
</body>
</html>
Почему вы используете "file_get_contents", вы можете использовать "include_once" для включения файла нижнего колонтитула.
Для вашего шаблона поставьте маркер для css и создайте свой массив css в php, а затем введите его в свой маркер.
Надеюсь, поможет.