2016/04/29 smarty模板 1, 初步 目标 : 变量 运算符 表达式 流程控制 函数
① 从配置文件中读取配置:
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, 初步 目标 : 变量 运算符 表达式 流程控制 函数的更多相关文章
- smarty模板 变量 运算符 表达式 流程控制 函数
① 从配置文件中读取配置: 1,在模板页面加载配置文件 html页面 不是php页面<{config_load file='fo.conf'}> 2,在需要用到配置的地方加<{#si ...
- 2016/04/29 ①cms分类 ② dede仿站制作 步骤 十个步骤 循环生成菜单 带子菜单的菜单 标签 栏目 栏目内容列表 内容图片列表
cms 系统还有: phpcms 企业站 Xiaocms 织梦 企业站 wordpress (博客) Ecshop 商城 Ecmall 多用户 Discms 记账 方维 订餐 团购 CMS ...
- PHP学习之[第04讲]PHP5.4 运算符、流程控制
一.运算符: 1.算数运算符:+.-.*./.%.++.-- 2.字符串运算符: <?php $str="string php100"; echo $str."we ...
- DAY 04运算符与流程控制
输入输出补充: python2与python3的输入输出不同 python2中有两种用户 输入方式,一种是raw_input,和input raw_input与python3的input是相同的 而p ...
- PHP(三)运算符、流程控制和函数初步
- 12月15日smarty模板基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
- smarty模板基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
- 学习图像算法阶段性总结 (附一键修图Demo) 2016.04.19更新demo
今天特别感慨,自己从决定研究图像处理,势必要做出一键修图算法. 经历了,三个多月的书籍积累,三个多月的算法调整以及优化. 人是一种奇怪的动物,当你做不到的时候,你以为做到了,自己会感觉很爽,很有成就感 ...
- Smarty模板
Smarty模板 是做什么用的?? 是将前端的显示和后台的逻辑进行分离,就相当于把前台显示的页面和后台要实现的某些功能的逻辑给分离出来了,分离在两个文件里,也就是说,前端只负责显示,后端只负责逻辑操作 ...
随机推荐
- redis:哨兵集群配置
最少配置1主2从3哨兵 一.引言 上一篇文章我们详细的讲解了Redis的主从集群模式,其实这个集群模式配置很简单,只需要在Slave的节点上进行配置,Master主节点的配置不需要做任何更改,但是有一 ...
- C语言程序内存分布
一个进程的数据在内存中的布局如下图: bss段(bss segment):可读可写不可执行,通常用来存放程序中未初始化的全局变量.bss是英文Block Started by Symbol的简称.b ...
- ARM Linux 3.x的设备树(Device Tree)(转)
http://blog.csdn.net/21cnbao/article/details/8457546
- nginx启动、重启、关闭、升级
一.启动 cd usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径 或者使用 cd /usr/local/ngin ...
- 大数据学习——mapreduce运营商日志增强
需求 1.对原始json数据进行解析,变成普通文本数据 2.求出每个人评分最高的3部电影 3.求出被评分次数最多的3部电影 数据 https://pan.baidu.com/s/1gPsQXVYSQE ...
- XTU 二分图和网络流 练习题 J. Drainage Ditches
J. Drainage Ditches Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Ja ...
- XV6第一个进程
第一个进程 本章通过第一个进程的创建来解释 xv6 是如何开始运行的,让我们得以一窥 xv6 提供的各个抽象是如何实现和交互的.xv6 尽量复用了普通操作的代码来建立第一个进程,避免单独为其撰写代码. ...
- left join 与left outer join的区别
joinn 语句有三种:inner join, left outer join 和 right outer join都可以简写,分别为join,left join,right join.
- Codeforces Round #386 (Div. 2) A+B+C+D!
A. Compote 水题(数据范围小都是水题),按照比例找最小的就行了,3min水过. int main() { int a,b,c; while(~scanf("%d%d%d" ...
- iOS-runtime-根据类名推送到任意控制器,且实现属性传值
// // WJRuntime.m // RuntimeSkip // // Created by tqh on 15/9/8. // Copyright (c) 2015年 tqh. All rig ...