smarty基本用法,循环,判断
require './smarty/Smarty.class.php'; $sm = new Smarty;
$sm->setTemplateDir("./dir");//设置模板路径
$sm->left_delimiter = '<{';//设置左右边界符
$sm->right_delimiter = '}>';
$sm->caching = true;//是否开启缓存
$sm->cache_lifetime = 120;//缓存生命周期
$d = "这个雨季,快结束吧2";
$arr = array('a'=>'小明','b'=>'大欧'); class A{
public $b='bbb';
}
$obj = new A(); $sm->assign('mytitle',$d);
$sm->assign('obj',$obj);
$sm->assign('t',$arr);
$sm->display('2.html');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
h1{font-size: 12px;}
</style>
</head>
<body>
<{Config_load file="xxx.conf"}>
<h1><{$smarty.config.bb}></h1>
<h1><{$mytitle}></h1>
<h1><{$t['a']}></h1>
<h1><{$t.a}></h1>
<h1><{$obj->b}></h1>
<h1><{$smarty.now}></h1>
<h1><{$smarty.get.id}></h1><!--获得$_GET['id'] -->
<h1></h1>
</body>
</html>
循环,判断
<?php
require './smarty/Smarty.class.php';
$sm = new Smarty;
$sm->setTemplateDir("./dir");//设置模板路径
$n = mt_rand(1,9); $arr = array(
array('id'=>1,'title'=>'小叶'),
array('id'=>2,'title'=>'小红'),
array('id'=>3,'title'=>'小刚')
); $sm->assign('n',$n);
$sm->assign('arr',$arr);
$sm->display('3.html');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{foreach $arr as $k=>$v}
{$v['id'] + 2}
{$v['title']}
{/foreach}
<h1>
{if $n == 5}您好啊5
{else if $n == 4}您好啊4
{else}您好啊other
{/if}
</h1>
</body>
</html>
smarty基本用法,循环,判断的更多相关文章
- Smarty基础用法
一.Smarty基础用法: 1.基础用法如下 include './smarty/Smarty.class.php';//引入smarty类 $smarty = new Smarty();//实例化s ...
- Python条件循环判断
1.条件判断语句 Python中条件选择语句的关键字为:if .elif .else这三个.其基本形式如下: 1 2 3 4 5 6 7 8 9 age_of_cc = 27 age = int( ...
- jquery for循环判断是否重复
//使用for循环 判断是否有重名 var len=$("li").length;//获取页面中所有li的数量 for(var i=0; i<len; i++){ oldna ...
- R语言学习——循环判断语句
循环 判断 函数 函数是一个对象,可以赋值 函数要放在调用函数的前面 输入输出 read.csv()------文本文件 csv是comma separated value的英文缩写,其读取逗号分隔 ...
- 关于pthread_cond_wait使用while循环判断的理解
在Stevens的<Unix 环境高级编程>中第11章线程关于pthread_cond_wait的介绍中有一个生产者-消费者的例子P311,在进入pthread_cond_wait前使用w ...
- if循环判断
if循环判断 if-else循环的语法格式 if 逻辑判断句: 代码块 # 缩进表示所属关系 else 逻辑判断句: 代码块 if 和elif同时使用来做多层判断 if 逻辑判断式: 代码块 ...
- JavaScript 循环判断练习题
JavaScript 循环判断练习题 小明有一组水果("苹果","梨子","香蕉","葡萄","西瓜" ...
- Python3+RobotFramewok 循环判断以及Evaluate用法(三)
本章主要介绍RF的循环,判断以及关键字Evaluate. 1. for循环 在RF中通过 :FOR 编写循环 :FOR ${i} in range 10 log ${i} @{list} create ...
- smarty -- foreach用法
{foreach},{foreachelse} 用于像访问序数数组一样访问关联数组 {foreach},{foreachelse} {foreach} is used to loop over an ...
随机推荐
- SSM配置Socket多线程编程(RFID签到实例)
1.SocketServiceLoader.java package cn.xydata.pharmacy.api.app.test; import javax.servlet.ServletCont ...
- Codeforces Round #423
这一次又崩了,最后只a了一题(还是被hack后才发现的错误) 第一题水题,多用一个数保存2-1后的数,注意先用2的桌子,再用这个 #include<map> #include<set ...
- laravel中composer镜像服务的方式
系统全局配置:即将配置信息添加到Composer的全局配置文件config.json中. 单个项目配置:将配置信息添加到某个项目的composer.json文件中. 例1:修改Composer的全局配 ...
- 十六、dbms_space_admin(提供了局部管理表空间的功能)
1.概述 作用:提供了局部管理表空间的功能 2.包的组成 1).segment_verify作用:用于检查段的区映像是否与位图一致语法:dbms_space_admin.segment_verify( ...
- iOS 数组集合操作(交集,并集,差集,子集)
1.求数组的 交集,并集,差集 NSArray *array1 = @[@"1",@"2",@"3"]; NSArray *array2 = ...
- intellij 出现“Usage of API documented as @since 1.6+”的解决办法(转)
原文链接:http://www.cnblogs.com/cxj20160928/p/5954196.html intellij 出现“Usage of API documented as @since ...
- LeetCode之Regular Expression Matching
[题目描述] Implement regular expression matching with support for '.' and '*'. '.' Matches any single ch ...
- encodeURI()和encodeURIcomponent()的共同点和不同点
共同点: 1.encodeURI和encodeURIcomponent都是Global对象, Global对象在某种意义上是违一个终极的兜底对象,换句话说,不属于任何其他对象的属性和方法,最终都是她的 ...
- RMI垃圾收集简介
和单机系统类似, 分布式系统也需要自动清除不再有客户端引用的对象(remote object). 远程对象的自动垃圾回收机制, 将程序员从深坑中解放出来, 不再需要人工跟踪client所引用的对象了. ...
- 创建Azure scheduler完成日常任务
Azure Scheduler 1. 登录portal,创建azure scheduler2. 选择任务类型.azure scheduler支持两种类型的任务.http :定时给一个url发请求sto ...