SMARTY框架的前台后台基本用法,函数的调用方式

SMARTY框架的前台后台基本用法,函数的调用方式

SMARTY

后台:

include 'smarty/libs/Smarty.class.php';//引入Smarty文件

$smarty = new Smarty;//实例化smarty对象

$smarty->assign('age', 23);//设置传递给前台的变量名和值

$smarty->assign('name', '张三');

$smarty->assign('sex', '男');

$smarty->setTemplateDir('view');//设置前台模板文件文件夹

$smarty->setLeftDelimiter('{{');//设置前端的左边定界符

$smarty->setRightDelimiter('}}');//设置前端的右边定界符

$smarty->setCompileDir('compile');//设置临时编译文件存放位置

$smarty->display('index.html');//显示模板文件夹下的 index.html 文件


前台:

{$arr[0]}

{$arr.1}

{$arr['name']}

{$arr.height}:数组调用方式 可用[] ,也可用 . 


{for $i=1 to 100}内容{/for}:循环

{foreach $arr as $k=>$v}内容{/foreach}:循环数组

{if $a==1}内容{elseif $a==2}内容{else}内容{/if}:if判断


{$str|lower}

{$str|upper}:字符串处理方式格式


{include file='footer.html'}:引入文件,路径相对于$smarty->setTemplateDir('view');


最后编辑于:2020/06/16作者: 牛逼PHP

发表评论