天天看点

PHP Smarty 内置函数 if、elseif、else

函数,根据功能的不同,在smarty中将函数分成三大类:

1、内置函数

2、变量修饰器

3、函数插件(自定义函数)

为什么需要内置函数?

针对一些复杂的输出,是需要借助于内置函数才可以。

还有一些其他的功能,比如config_load,literal等。

常用的内置函数有哪一些?

PHP Smarty 内置函数 if、elseif、else

if.php(后端):

<?php
include "libs/Smarty.class.php";
$smarty = new Smarty();
$smarty->template_dir = "templates";
$smarty->compile_dir = "templates_c";
//分配数据
$smarty->assign('iq',60);
$smarty->display("if.tpl");
           

if.tpl(前端视图):

<!DOCTYPE html>
<html >
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<h2>if相关函数的使用</h2>
	<p>你的IQ是:{$iq}</p>
	<p>适合你的武功秘籍是:
		{if $iq >= 130} 
			乾坤大挪移
		{elseif $iq < 130 && $iq >= 110}
			九阳神功
		{elseif $iq < 110 && $iq >= 90}
			降龙十八掌
		{elseif $iq < 90 && $iq >= 70}
			打狗棒法
		{else}
			葵花宝典
		{/if}   {* if必须要有关闭 *}
	</p>
</body>
</html>