惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 师太

10个月没来了。。。 跑在路上 看内容 泪水模糊双眼 [PHP]找了半天的自动转义问题 我在反省 We are not yong any more! linux上安装php+oci的一些总结 挫败感 我等你炒我鱿鱼还是我先炒你鱿鱼? 让暴风雨来得更猛烈些吧 个人感言 PHP 框架 推荐: MindManager(思维导图) 推荐: MicroOLAP Database Designer for MySQL 一个人的战役 春节 hard hard hard Oyeme(最近迷上了这一首歌)
phplib多行多列(嵌套block)
师太 · 2008-08-13 · via 博客园 - 师太

定义嵌套block

来源: http://www.x2blog.cn/maxwin/7311.html
test.html代码

<table>
 <!-- BEGIN tr -->
  <tr>
   <!-- BEGIN td -->
    <td>{myVar}</td>
   <!-- END td -->
  </tr>
 <!-- END tr -->
</table>

//这里用tr、td命名block名纯属为了好理解

test.php中定义block

//定义mbody中的block: tr, 命名为mtr
$t
->set_block('mbody', 'tr', 'mtr');
//定义block中的子block: td, 命名为mtd
$t
->set_block('tr', 'td', 'mtd');

完整的test.php代码如下:

<?php
//包含头文件
require
('template.php');//设置模板调用目录: ./ 表示就为当前目录
$t 
= new Template('./');//调用test.html, 并将其命名为mbody
$t
->set_file('mbody', 'test.html');//定义mbody中的block: tr, 命名为mtr
$t
->set_block('mbody', 'tr', 'mtr');
//定义block中的子block: td, 命名为mtd
$t
->set_block('tr', 'td', 'mtd');//0-14 共15个数字分别填在表格中
for ($i = 0; $i < 15; $i++) {
     $t
->set_var('myVar', $i);
    
    
//每次都要生成一列,所以每次解析一次td
     $t
->parse('mtd', 'td', true);
    
    
//当到达3列是就要换行了,解析一次tr
    
if ($i%3 == 2) {    //这个是换行的条件
         $t
->parse('mtr', 'tr', true);
        
        
//以下这个请注意: 将mtd的值置空。
        
//这里是个人理解,可能不太准确:因为每次解析td都相当于 mtd += td, 即每次都是把生成的td内容加到mtd后面,当对tr解析时就将其子block生成的所有内容解析为自己的。因此当一行完成时改行所有td都在mtd里面,如果不将mtd置空,下一行的td内容仍然在其基础上增加,就会出现(*1)的情况
         $t
->set_var('mtd', '');
    
}
}//pparse = parse + p  解析并输出mbody
$t
->pparse('mout', 'mbody');
?>

正常的情况输出为:

0 1 2
3 4 5
6 7 8
9 10 11
12 13 14

异常情况:没有将mtd置空的情况(*1)

0 1 2
0 1 2 3 4 5
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9 10 11
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14