albertoadolfo27 / friendly_template
用于创建HTML模板的PHP库
1.0.0
2023-07-30 20:50 UTC
Requires
- php: >=8.0
README
用于创建HTML模板的PHP库
入门
最低要求
- PHP >= 8.0
安装
使用 composer 安装
composer require albertoadolfo27/friendly_template
快速示例
绘制模板
- 1. index.php 文件
<?php // Require the Composer autoloader. require_once "vendor/autoload.php"; use FriendlyTemplate\Template; // Instantiate a Template, passing the base directory of the template files. $template = new Template("views/"); // Draw the Header $template->draw("header", array("title" => "Hello World!")); // Draw the Main Content $template->draw("content", array("user" => "John Doe")); // Draw the Footer $template->draw("footer.php");
- 2. header.php 文件,位于 views/ 目录下
<!DOCTYPE html> <html lang="en"> <head> <title><?php echo $title; ?></title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="views/styles/style.css"> </head> <body> <div class="topnav"> <a href="#">Link</a> <a href="#">Link</a> <a href="#">Link</a> </div>
- 3. content.php 文件,位于 views/ 目录下
<div class="content"> <h2>Content Template</h2> <p>Welcome <b><?php echo $user; ?></b></p> </div>
- 4. footer.php 文件,位于 views/ 目录下
<div class="footer">
<p>Footer</p>
</div>
</body>
</html>