Home Backend Development PHP Tutorial PEAR里HTML_Template_IT摸板类的用法_PHP

PEAR里HTML_Template_IT摸板类的用法_PHP

Jun 01, 2016 pm 12:40 PM
Block method template usage symbol return

PEAR里的HTML_Template_IT是一个简单而且容易使用的类。


********** 建立一个模板文件 ****************
“符号”命名规则 为下面的正则表达式:
{[0-9A-Za-z_-]+}
”块“ 格式为下面的,块名的命名规则和“符号”一样的:

... 块内容 ...

块允许嵌套,你必须首先设置并分析最内层的块,然后再设置和分析上一层的块。





*********** 主要方法 ***********
构造函数:
void IntegratedTemplate::IntegratedTemplate ([string $root = ""])
$root = 摸板根目录
你也可以用
void IntegratedTemplate::setRoot (string $root)
方法设置模板目录;该方法不能被静态调用。
---------------------------------------------------------
加载模板:
boolean IntegratedTemplate::loadTemplatefile (string $filename, boolean [$removeUnknownVariables = TRUE], boolean [$removeEmptyBlocks = TRUE])
$filename = 模板文件名
$removeUnknownVariables = 设置是否移除未知的变量
$removeEmptyBlocks = 设置是否移除空块
成功返回TRUE,失败返回FALSE。
该方法不能被静态调用
-------------------------------------------------------
指定当前要处理的块:
boolean IntegratedTemplate::setCurrentBlock ([string $block = "__global"])
$block = 块名
成功返回TRUE,失败会返回一个PEAR_Error对象,里面包含错误
描述。该方法不能被静态调用。
-------------------------------------------------------
用变量替换当前要处理的块里的“符号”:
void IntegratedTemplate::setVariable (mixed $placeholder [, mixed $variable = ""])
$placeholder = 要替换的符号名,如果$variable是一个数组,
那就用符号名作为这个数组的索引并用这个索
引的数组元素的数据替换符号
$variable = 变量名或数组名
该函数不能被静态调用
--------------------------------------------------------
分析当前正处理的块:
void IntegratedTemplate::parseCurrentBlock ()
失败会返回一个PEAR_Error对象,里面包含错误
描述。该方法不能被静态调用。
---------------------------------------------------------
处理完成输出:
void IntegratedTemplate::show ([string $block])
$block = 要返回的块
如果没设置$block,将返回完整的模板


******************* 简单示例(示例来自PEAR的在线手册)*****
Usage Example
Example 25-1. main.tpl.htm模板文件,在"./templates"目录下











{DATA}




Example 25-2. PHP脚本

require_once "HTML/Template/IT.php";

$data = array
(
"0" => array("Stig", "Bakken"),
"1" => array("Martin", "Jansen"),
"2" => array("Alexander", "Merz")
);

$tpl = new HTML_Template_IT("./templates");

$tpl->loadTemplatefile("main.tpl.htm", true, true);

foreach($data as $name) {
foreach($name as $cell) {
// Assign data to the inner block
$tpl->setCurrentBlock("cell") ;
$tpl->setVariable("DATA", $cell) ;
$tpl->parseCurrentBlock("cell") ;
}
// Assign data and the inner block to the
// outer block
$tpl->setCurrentBlock("row") ;
$tpl->parseCurrentBlock("row") ;
}
// 输出
$tpl->show();

?>


Example 25-3. 输出
















Stig

Bakken

Martin

Jansen

Alexander

Merz



*******************************************************
HTML_Template_IT里面还有一个ITX类,可以完成更加复杂的功能,
继承自IT类;ITX。PHP文件的原代码里包含了这个类的方法说明。

关于HTML_Template_IT其他方法的详细说明请参见PEAR的手册,地址为
http://pear.php.net/manual/en/package.html.html-template-it.php

--希望大家能好好利用PEAR这个库写出更多更好的PHP程序!--
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. Mar 28, 2024 pm 12:50 PM

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Moondrop releases Block true wireless earbuds with low-latency game mode Moondrop releases Block true wireless earbuds with low-latency game mode Aug 10, 2024 pm 03:31 PM

Moondrop has released the Block true wireless earbuds for audio enthusiasts that sit comfortably in the outer ear. Unlike earbuds jammed into ear canals, the Block does not cause a plugged ear feeling or collect ear wax. The 13 mm driver is enclosed

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

Quickly master: How to open two WeChat accounts on Huawei mobile phones revealed! Quickly master: How to open two WeChat accounts on Huawei mobile phones revealed! Mar 23, 2024 am 10:42 AM

In today's society, mobile phones have become an indispensable part of our lives. As an important tool for our daily communication, work, and life, WeChat is often used. However, it may be necessary to separate two WeChat accounts when handling different transactions, which requires the mobile phone to support logging in to two WeChat accounts at the same time. As a well-known domestic brand, Huawei mobile phones are used by many people. So what is the method to open two WeChat accounts on Huawei mobile phones? Let’s reveal the secret of this method. First of all, you need to use two WeChat accounts at the same time on your Huawei mobile phone. The easiest way is to

The difference between Go language methods and functions and analysis of application scenarios The difference between Go language methods and functions and analysis of application scenarios Apr 04, 2024 am 09:24 AM

The difference between Go language methods and functions lies in their association with structures: methods are associated with structures and are used to operate structure data or methods; functions are independent of types and are used to perform general operations.

How to add PPT mask How to add PPT mask Mar 20, 2024 pm 12:28 PM

Regarding PPT masking, many people must be unfamiliar with it. Most people do not understand it thoroughly when making PPT, but just make it up to make what they like. Therefore, many people do not know what PPT masking means, nor do they understand it. I know what this mask does, and I don’t even know that it can make the picture less monotonous. Friends who want to learn, come and learn, and add some PPT masks to your PPT pictures. Make it less monotonous. So, how to add a PPT mask? Please read below. 1. First we open PPT, select a blank picture, then right-click [Set Background Format] and select a solid color. 2. Click [Insert], word art, enter the word 3. Click [Insert], click [Shape]

See all articles