Home php教程 php手册 PEAR里HTML_Template_IT摸板类的用法

PEAR里HTML_Template_IT摸板类的用法

Jun 13, 2016 am 10:27 AM
html pear template yes usage of Simple

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脚本 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)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles