我正在为对代码知之甚少的人编写一个单页登录器。因此,我想在需要定制的部分,比如<title></title>
和网站上的一些标题,以及另一个php文件中的一些URL,让它变得非常用户友好。
我的想法是制作一个主文件,让我们称之为main_file.php
以使其变得简单。
在main_file.php
中,我想要:(例如)
$title = "web page title here";
$headline = "headline here"
$URL1 = "http://a custom url here.com";
etc
并将上述echo
’d放在正确的文件中。
这样做的目的是,我为之编码的用户只需要编辑一个清晰的文件,并根据需要提供说明等。
就这么做吧。
您的配置文件是main_file.php
,对吗?
your-application/main_file.php
然后,您有一个主布局/模板,例如:
your-application/index.php
在这种布局中,您可以在第一行中包括主文件:
<?php include ('main_file.php'); ?>
<!-- the rest of the code below -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php echo $title ?></title>
</head>
<body>
<h1><?php echo $page_tile ?></h1>
<p><?php echo $some_text_variable ?></p>
</body>
</html>
完成!
main_file.php
中声明的所有变量现在都可以在index.php
中使用。
- 模板/布局文件必须是php文件,但您可以将html放在里面,明白吗