0%

PHP Smarty的if语句

模板index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{$title}</title>
</head>
<body>
{if $scope>=90}
优秀
{elseif $scope>=70}
一般
{elseif $scope>=60}
及格
{else}
不及格
{/if}
</body>
</html>

判断结束需要关闭标签. index.php

<?php
require_once 'libs/Smarty.class.php';
//引入Smarty类
$smarty=new Smarty();
//初始化
$smarty->assign("title","标题");
//设置变量
$smarty->assign("scope",30);
$smarty->display("index.html");
//显示
?>