php 模板 class x_tiny_tpl

码农软件 · 软件分类 · 模板引擎 · 2019-08-22 18:28:14

软件介绍

这是一个php模板class,之前我一直使用(Ease Template:http://www.systn.com/data/et/1.html),后因不支持php7,然后就重写了。

XTinyTpl和Ease Template语法类似,功能相对少了一些,主要是自用,因现在不经常用php,所以维护不及时,请谅解。

php版本:php5.3以上

**XTinyTpl文件小,运行速度快。支持模板变量、循环、判断、php函数、php代码段。**

使用说明请查看:doc.html

PHP:

<?php
include('lib/XTinyTpl.class.php');
$tpl = new XTinyTpl(array(
	'rootPath' => dirname(__FILE__),
	'webPath' => '/test/xtpl',
	'tplPath' => 'tpl',
	'cachePath' => 'cache',
	'extName' => '.html',
	'regGlobal' => true,
	'mergeInclude' => false
));

$list = array(
	array(
		'name' => '张三',
		'list' => array(
			array(
				'sub_name' => 'aaa1'
			),
			array(
				'sub_name' => 'aaa2'
			)
		)
	),
	array(
		'name' => '李四',
		'list' => array(
			array(
				'sub_name' => 'bbb1'
			),
			array(
				'sub_name' => 'bbb2'
			)
		)
	)
);
$tpl->setVar('a', 1);
$tpl->setVar($list);
$tpl->setVar(   
	array(  
		'var1'=>'123456',   
		'var2'=>'abcdefg',
	)
);


$tpl->out('test/test');

模板:

<!-- #include file="/inc/header.html" -->

<div class="item">
	<div class="title">变量</div>
	<div class="info">
		<div class="preview">
			变量1:{$var1}<br>
			变量2:{$var2}-${var2}<br>
			变量2:${substr($var1, 0, 3)}
		</div>	
	</div>
</div>

<div class="item">
	<div class="title">循环</div>
	<div class="info">
		<div class="preview">
			<ul>
			<!-- $list AS $k => $v -->
				<li>${k}--${v['name']}
					<ul>
					<!-- $list AS $v2 -->
						<li>	${v2['name']}</li>
					<!-- end -->
					</ul>
				</li>
			<!-- end -->
			</ul>

			<!-- while:$i<10 -->  
				<!--{$i++;}-->
				${i},
			<!-- end -->
		</div>
	</div>
</div>

<div class="item">
	<div class="title">逻辑判断</div>
	<div class="info">
		<div class="preview">
			<!-- IF[$a==1] -->   
			变量a为${a} 
			<!-- ELSE IF[$a==2] -->   
			变量a为${a}  
			<!-- ELSE -->   
			变量a为空   
			<!-- END -->   
		</div>
	</div>
</div>

<div class="item">
	<div class="title">内部引用</div>
	<div class="info">
		<div class="preview">
			<!-- #include file="/inc2/header_sub.html" -->
			{inc:/inc2/header_sub}
			<!-- inc:inc2/header_sub --> 
			{include file="/inc2/header_sub"}
		</div>
	</div>
</div>
<div class="item">
	<div class="title">路径解析</div>
	<div class="info">
		<pre class="code">
通过 $opt['path_replace'] = array('images'); 配置相对路径,程序会自动加上绝对路径。这样的好处是在做页面时,页面可直接浏览器预览
		</pre>
		<div class="preview">
			src="images/aaa.png"
		</div>
	</div>
</div>
<div class="item">
	<div class="title">嵌入PHP代码</div>
	<div class="info">
		<div class="preview">
			时间处理:{run:}echo date('Y-m-d H:i',time()){/run}  
			<br>   
			时间处理2:<!-- run: -->echo date('Y-m-d H:i:s',time())<!-- /run -->   
			<br>   
			条件判断1:{run:}if($a==1){echo '成立';}else{echo '失败';}{/run}   
			<br>   
			条件判断2:<!-- run: -->if($a==1){echo '成立';}else{echo '失败';}<!-- /run -->   
			<br>   
			条件判断3:${($a==1)?'成立':'失败'}
			<br>   
			条件判断4:<!--{echo ($a==1)?'成立':'失败';}--> 
		</div>
	</div>
</div>

本文地址:https://codercto.com/soft/d/12942.html

The Filter Bubble

The Filter Bubble

Eli Pariser / Penguin Press / 2011-5-12 / GBP 16.45

In December 2009, Google began customizing its search results for each user. Instead of giving you the most broadly popular result, Google now tries to predict what you are most likely to click on. Ac......一起来看看 《The Filter Bubble》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具