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

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. word break和word wrap

    默认情况下,如果同一行中某个单词太长了,它就会被默认移动到下一行去: word break(normal | break-all | keep-all):表示断词的方式 word wrap(norma ...

  2. vue 项目部署

    vue项目部署到PHP项目 入口目录 vue项目打包后, 是一个单文件html 我们只需要把打包后的文件夹放在php项目的public下面 访问 xxx.com/h5/index.html 就可以访问 ...

  3. LeetCode(10) Regular Expression Matching

    题目 Implement regular expression matching with support for '.' and '*'. '.' Matches any single charac ...

  4. 杭电 1596 find the safest road (最小路径变形求最大安全度)

    Description XX星球有很多城市,每个城市之间有一条或多条飞行通道,但是并不是所有的路都是很安全的,每一条路有一个安全系数s,s是在 0 和 1 间的实数(包括0,1),一条从u 到 v 的 ...

  5. Farthest Nodes in a Tree (求树的直径)

    题目链接,密码:hpu Description Given a tree (a connected graph with no cycles), you have to find the farthe ...

  6. 最近的一些JAVA基础知识

    1,关于判断两个值是否相等 equal 和==是有区别到 2,判断一个数组集合 List是否为空 这个不能用"==null或者equal"要用isEmpty() , 对于不等于加一 ...

  7. JSP配置即报错以及解决办法(未更新完)

    JSP: JAVA Server Page  使用JAVA语言编写的一种在服务器运行的动态页面 JSP = JAVA + HTML JSP 的执行过程 1: 翻译阶段  把JSP源文件翻译成 java ...

  8. Couchbase第一印象(架构特性)

    Couchbase第一印象(架构特性) 面向文档 保存的字节流总有一个 DOCUMENT ID(Object_ID) 高并发性,高灵活性,高拓展性,容错性好 面向文档的集群存储系统 每个文档用一个唯一 ...

  9. Python+selenium常用方法(Webdriver API)

    小编整理了目前学习的Python+selenium常用的一些方法函数,以后有新增再随时更新. 加载浏览器驱动: webdriver.Firefox() 打开页面:get() 关闭浏览器:quit() ...

  10. 75. Spring Boot 定制URL匹配规则【从零开始学Spring Boot】

    在之前有一篇文章说了,博客名称从原来的<从零开始学Spring Boot>更改为<Spring Boot常见异常汇总>,后来写了几篇文章之后发展,有些文章还是一些知识点,所以后 ...