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

推荐订阅源

T
Tailwind CSS Blog
月光博客
月光博客
Recent Announcements
Recent Announcements
S
Secure Thoughts
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Troy Hunt's Blog
量子位
Cloudbric
Cloudbric
L
LINUX DO - 最新话题
S
Security @ Cisco Blogs
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
WordPress大学
WordPress大学
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog
Engineering at Meta
Engineering at Meta
P
Privacy & Cybersecurity Law Blog
aimingoo的专栏
aimingoo的专栏
PCI Perspectives
PCI Perspectives
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V2EX - 技术
V2EX - 技术
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
Darknet – Hacking Tools, Hacker News & Cyber Security
U
Unit 42
Schneier on Security
Schneier on Security
大猫的无限游戏
大猫的无限游戏
I
Intezer
Hacker News: Ask HN
Hacker News: Ask HN
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Help Net Security
Latest news
Latest news
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LangChain Blog
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
小众软件
小众软件
M
MIT News - Artificial intelligence
A
About on SuperTechFans
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
NISL@THU
NISL@THU
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
T
Tenable Blog

博客园 - 师太

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