SoFunction
Updated on 2025-04-04

php Http_Template_IT class library for template replacement

Two simple templates:
Copy the codeThe code is as follows:

<html>
<head>
<title>{title}</title>
</head>
<body>
<font color=red size=6><center>{title}</center></font>
<hr>
<pre>{body}</pre>
</body>
</html>

Copy the codeThe code is as follows:

<html>
<head>
<title>{title}</title>
</head>
<body>
<font color=green size=7><center>{title}</center></font>
<pre>{body}</pre>
</body>
</html>

The Http_Template_IT class library must be installed first
Copy the codeThe code is as follows:

<?php
require_once "HTML/Template/";
//Create a new HTML_Template_IT object, where the parameter is the path where the template file is located
$template = new HTML_Template_IT('templates/');
//Read the template file and obtain template information by reading the parameters on the address bar
$template->loadTemplateFile($_GET['template'].".htm");
//Set the parameters in the template
$template->setVariable('title', 'HTML_Template_IT');
$template->setVariable('body', 'Hello World');
//Show page
$template->show();
?>

Write the following in the browser and you will find the template replacement effect:
http://localhost:8082/file:/F:/php/phpcode/23/23.4.3/23.4.?template=T2
http://localhost:8082/file:/F:/php/phpcode/23/23.4.3/23.4.?template=T1