Home > PHP Framework > ThinkPHP > body text

How to render thinkphp5 public page

PHPz
Release: 2023-04-11 14:33:24
Original
801 people have browsed it

ThinkPHP5 is a powerful PHP development framework with the advantages of easy to learn, easy to use, efficient and stable. In the development model where the front and back ends are separated, the front end usually needs to introduce some public pages, such as the header, bottom, navigation bar, etc. So, how to render public pages in ThinkPHP5? Below I will introduce how to operate it.

1. Use the include statement

include is a function of PHP that can include the contents of the specified file into the current PHP file. Therefore, we can use the include statement to introduce the code of the public page where we need to render the public page. For example:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>首页 - MyWeb</title>
</head>
<body>
<?php include(&#39;header.html&#39;); ?>
<!-- 此处为页面内容 -->
<?php include(&#39;footer.html&#39;); ?>
</body>
</html>
Copy after login

In the above code, two public pages, header.html and footer.html, are introduced into the HTML file through the include statement.

2. Use template engine

ThinkPHP5 has a built-in PHP template engine, which can use template syntax when writing HTML code to separate front-end code and back-end code, improving development efficiency and Code maintainability. In the template engine, we can use the include tag to introduce public pages. For example:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>首页 - MyWeb</title>
</head>
<body>
{include file="header.html"}
<!-- 此处为页面内容 -->
{include file="footer.html"}
</body>
</html>
Copy after login

In the above code, {include file="header.html"} and {include file="footer.html"} are introduced respectively There are two public pages, header.html and footer.html.

Summary

The above are two common methods for rendering public pages in ThinkPHP5. The first method is suitable for simple scenarios and small projects; the second method is suitable for large projects and has better maintainability and scalability. More importantly, with the continuous development and advancement of front-end technology, we can use more tools and technologies to achieve front-end and back-end separation, improving development efficiency and user experience.

The above is the detailed content of How to render thinkphp5 public page. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!