① 从配置文件中读取配置:

1,在模板页面加载配置文件 html页面 不是php页面
<{config_load file='fo.conf'}>

2,在需要用到配置的地方加
<{#size#}>

3, 如果配置文件分了块,要取某一块的配置 用到section

<{config_load file='aa.conf' section='aa'}>

② 调用变量调节器: |

capitalize 单词首字母大写<{$test|capitalize}

 cat  连接字符串   <{$articleTitle|cat:" yesterday."}>

lower 小写    <{$articleTitle|lower}>   类如upper

truncate   截取   <{$articleTitle|truncate:30}>

③ 自定义变量调节器:

1,在自定义的插件目录下新建文件,注意命名规则 (plugins插件文件夹下)

modifier.mark.php

2,在以上文件里面新建方法: 注意命名规则

smarty_modifier_mark

该方法必须有一个参数,代表变量本身

例:

该方法必须有一个参数,这个参数代表变量本身

function smarty_modifier_mark($str)
{
return "<mark>{$str}</mark>";

}

操作练习 :   0429test.php 中需要用到 DBDA.php 连接数据库  最后输出民族下拉菜单

1, 0429test.php

$smarty->assign(); 负责分配变量    和    $smarty->display();负责显示

 <?php 

 include("init.inc.php");//引入配置文件
$attr=array("a"=>"aa","b"=>"bb","c"=>"cc");//注册关联数组
$smarty->assign("attr",$attr);//注册数组
$smarty->assign("title","helloword");//注册字符串 $smarty->assign("test","thisfjasdjfajsdfjlasdjlfjlsdjfdsjlkfjskldj");//注册字符串
$smarty->assign("try1","this is a test");
$smarty->assign("money","美元"); $smarty->assign("bs",1); $r=new Ren();
$smarty->assign("ren",$r);//注册对象 调对象要用$ren->name include("DBDA.php");
$db=new DBDA();
$sql="select * from Nation";
$attrr=$db->Query($sql,1,"test2"); $smarty->assign("nation",$attrr); $smarty->display("0429test.html"); class Ren
{
public $name='张三';
}

2, 0429test.html   属性配置调用    调节器    foreach循环   if语句  保留函数  类中变量调用

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><{$title}></title>
</head>
<body> <{config_load file='fo.conf' section=bb}>
<div style="width:200px; height:200px; background-color:<{#bg#}>;font-size:<{#size#}>px">测试config</div> <{config_load file='fo.conf' section=aa}>
<div style="width:200px; height:200px; background-color:<{#bg#}>;font-size:<{#size#}>px">测试config</div>
<hr> <div style="width:200px; height:200px; background-color:<{$smarty.config.bg}>;font-size:<{#size#}>px">测试config</div> <h1>测试页面</h1>
<div><{$attr["a"]}></div>
<div><{$attr["b"]}></div>
<div><{$attr["c"]}></div> <div><{$attr.a}></div> <div><{$test|substr:10}></div>
<div><{$test|mark}></div>
<div><{$try1|capitalize}></div>
<div><{$money|cat:"$"}></div> <select>
<{foreach $attr as $k=>$v}>
<option><{$k}>=><{$v}></option>
<{/foreach}>
</select> <select>
<{foreach $attr as $k=>$v}>
<option><{$v@index}></option>
<{/foreach}>
</select> <select>
<{foreach $attr as $k=>$v}>
<option><{$v@iteration}></option>
<{/foreach}>
</select> <{foreach $attr as $k=>$v}>
<{if $v@first}>
<div style='width:40px; height:40px; background-color:yellow'><{$k}>=><{$v}></div>
<{else}>
<div style='width:40px; height:40px; background-color:red'><{$k}>=><{$v}></div>
<{/if}>
<{/foreach}> <div><{$ren->name}></div>
<div><{$smarty.now}></div>
<div><{$smarty.now|date_format}></div>
<div><{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}></div> <{if $bs==1}>
<div>bs=1</div>
<{else}>
<div>bs无</div> <{/if}> <select>
<{foreach $nation as $vv}>
<option value='<{$vv[0]}>'><{$vv[1]}></option>
<{/foreach}>
</select>
</body>
</html>

显示效果:

2016/04/29 smarty模板 1, 初步 目标 : 变量 运算符 表达式 流程控制 函数的更多相关文章

  1. smarty模板 变量 运算符 表达式 流程控制 函数

    ① 从配置文件中读取配置: 1,在模板页面加载配置文件 html页面 不是php页面<{config_load file='fo.conf'}> 2,在需要用到配置的地方加<{#si ...

  2. 2016/04/29 ①cms分类 ② dede仿站制作 步骤 十个步骤 循环生成菜单 带子菜单的菜单 标签 栏目 栏目内容列表 内容图片列表

    cms 系统还有: phpcms     企业站 Xiaocms  织梦  企业站 wordpress (博客) Ecshop 商城 Ecmall 多用户 Discms 记账 方维 订餐 团购 CMS ...

  3. PHP学习之[第04讲]PHP5.4 运算符、流程控制

    一.运算符: 1.算数运算符:+.-.*./.%.++.-- 2.字符串运算符: <?php $str="string php100"; echo $str."we ...

  4. DAY 04运算符与流程控制

    输入输出补充: python2与python3的输入输出不同 python2中有两种用户 输入方式,一种是raw_input,和input raw_input与python3的input是相同的 而p ...

  5. PHP(三)运算符、流程控制和函数初步

  6. 12月15日smarty模板基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  7. smarty模板基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  8. 学习图像算法阶段性总结 (附一键修图Demo) 2016.04.19更新demo

    今天特别感慨,自己从决定研究图像处理,势必要做出一键修图算法. 经历了,三个多月的书籍积累,三个多月的算法调整以及优化. 人是一种奇怪的动物,当你做不到的时候,你以为做到了,自己会感觉很爽,很有成就感 ...

  9. Smarty模板

    Smarty模板 是做什么用的?? 是将前端的显示和后台的逻辑进行分离,就相当于把前台显示的页面和后台要实现的某些功能的逻辑给分离出来了,分离在两个文件里,也就是说,前端只负责显示,后端只负责逻辑操作 ...

随机推荐

  1. tabl-cell

    参考:http://www.cnblogs.com/StormSpirit/archive/2012/10/24/2736453.html 总结特点 多个并排的table-cell始终等高. 宽度可以 ...

  2. POJ 2251-Dungeon Master (三维空间求最短路径)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  3. SpringMVC最核心

    如图所示:

  4. mysql语句查询:查询距离某个日期10天的数据

    select * from table  where state = '1' and DATE_SUB(CURDATE(), INTERVAL 10 DAY) <= begin_time

  5. 新建oracle连接远程服务

    更新下面两个文件夹中的 D:\app\shisan\product\11.2.0\client_1\network\admin D:\ORACLE\product\11.2.0\dbhome_1\NE ...

  6. 【02】koala编译中文出错(已放弃不用)

    http://koala-app.com/index-zh.html koala 下载地址.     sass.中文编译出错: 打开 Koala文件夹位置->rubygems->gems- ...

  7. MySQL报错The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents

    参考资料:https://blog.csdn.net/qq_37630354/article/details/82814330 在property里加上最后这个参数即可

  8. PHP统计目录中文件个数和文件大小

    <meta charset="utf-8"><?php $dirn = 0; //目录数 $filen = 0; //文件数 //用来统计一个目录下的文件和目录的 ...

  9. 骑士精神 (codevs 2449)

    题目描述 Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士, 且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐标相差为1,纵坐标相差为2或者横坐标 ...

  10. poj1376 bfs,机器人

    开始时候有点怕, 感觉什么也不会,不过静下来思考思考也就想出来了,一个简单的BFS即可,但是由于队列没有重判,一直爆队列(MLE!)下次一定要注意! (bfs第一次到达便最优?) #include&l ...