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

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. @ApiParam @RequestParam @PathVariable 用法

    文章来源:https://www.cnblogs.com/hello-tl/p/9204279.html 1.@ApiParam ,是注解api的参数 ,也就是用于swagger提供开发者文档 ,文档 ...

  2. 阿里云配置tomcat后不能访问问题

    问题:使用阿里云centos 7.2配置好tomcat后,启动时间9分多钟,停在webapps下的manage这里近9分多钟 解决:进入 /usr/local/jdk1.8.0_144/jre/lib ...

  3. Codeforces 879C/878A - Short Program

    传送门:http://codeforces.com/contest/879/problem/C 本题是一个位运算问题——位运算的等价变换. 假设位运算符“&”“|”“^”是左结合的,且优先级相 ...

  4. 关于构造函数什么值传递给他的实例,只有this和prototype

    var a= function (){var bb = 12; this.aa ="xxx"}; a.aa="www"; a.prototype.cc=&quo ...

  5. hihoCoder#1141 二分·归并排序之逆序对

    原题地址 又是一道WA成狗的题,最后发现原来是结果溢出了.. 代码: #include <iostream> #include <cstring> using namespac ...

  6. HDU 3932 模拟退火

    HDU3932 题目大意:给定一堆点,找到一个点的位置使这个点到所有点中的最大距离最小 简单的模拟退火即可 #include <iostream> #include <cstdio& ...

  7. [luoguP1783] 海滩防御(二分 || 最短路 || 最小生成树)

    传送门 因为答案满足单调性,所以看到这个题,第一反应是二分,但是总是WA,也没有超时. 看了题解,,,,,, 这题刚开始很多人会想到二分,二分答案,然后看看是否能绕过所有信号塔,但是,这样写明显超时, ...

  8. MySQL性能优化的21个最佳实践 和 mysql使用索引【转载】

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...

  9. c++ 实现 key-value缓存数据结构

    c++ 实现 key-value缓存数据结构 概述 最近在阅读Memcached的源代码,今天借鉴部分设计思想简单的实现了一个keyvalue缓存. 哈希表部分使用了unordered_map,用于实 ...

  10. HDU 1041

    题意: 给原始序列1 给定变化规则是,对于原来的序列每一个0前边插入1,每个1前边插入0. 问原始序列经过n次变化之后有多少对相邻的0. 规律题: 从第二次开始 当第奇数次变化之后,数量变成原来数量的 ...