SMARTY核心
http://smarty.php.net/manual/en/
1.配置
define("ROOTPATH",dirname(__FILE__)."/../");
require_on
/**
* Smarty Template Class Initializtion
*/
if( @constant( "ENABLED_TPL" ) ) {
$obj_smarty = new Smarty();
$obj_smarty->compile_check = true; //Open Compile Check
$obj_smarty->debugging = false;// false || DEBUG || DEBUG_TPL; //debug On-off
$obj_smarty->template_dir = ROOT_PATH."html"; //Set Template Document Root
$obj_smarty->compile_dir = ROOT_PATH."cache"; //Set Template Cache File Document Root
$obj_smarty->left_delimiter = "<!!"; //Set Template Left Delimiter
$obj_smarty->right_delimiter = "!!>"; //Set Template Right Delimiter
/**
* 0:Smarty默认值,表示不对模板进行缓存
* 1:表示Smarty将使用当前定义的cache_lifetime来决定是否结束cache
* 2:表示Smarty将使用在cache被建立时使用cache_lifetime这个值
* 习惯上使用true与false来表示是否进行缓存
*/
$obj_smarty->caching = true;
$obj_smarty->cache_lifetime = 60 * 60 * 24;//-1:缓存从不过期,0:每次执行缓存总是被重新建立
}
2.循环,section,sectionelse
<!!sectionelse!!> 用来表示传入的数组变量为空时对模板进行的处理。
<!!section name=on
<!!$arr_result[on
<!!$smarty.section.on
<!!$smarty.section.on
<!!$smarty.section.on
<!!$smarty.section.on
<!!$smarty.section.on
<!!$smarty.section.on
<!!$smarty.section.on
<!!$smarty.section.name.rownum+$offset!!>//display the current loop iteration, starting with on
<!!/section!!>
<!!section name=on
<input type="checkbox" name="<!!$name!!>[]" id="<!!$name!!>_<!!$smarty.section.on
<!!if ($arr_result[on
<!!/section!!>
<!!section name=on
<option value="<!!$arr_result[opt].value!!>" <!!if $arr_result[on
<!!/section!!>
表格排版 1行2列
<!!if $smarty.section.on
<!!if $smarty.section.on
奇偶数用于斑马线效果
<!!if $smarty.section.on
生成斑马线
<div style="background:<!!cycle values='#F0F8FF,#F0FFFF,#FFFAF0,#F0FFF0'!!>" id="div_msg_<!!$smarty.section.on
...
</div>
3.表格,html_table table_foreach
<!!html_table cols=4 table_attr=' width="95%" border="0" cellspacing="0"
cellpadding="2" ' tr_attr=' align="left" valign="top" ' td_attr=' width="25%" ' loop=$arr_result!!>
<!!table_foreach from=$addproducts item=sam key=id cols=4 table_attr='width="100%" border="0" cellspacing="4"
cellpadding="0"' tr_attr='' td_attr=' width="25%"align="center" valign=""'!!>
<a href="<!!$sam.adurl!!>">
<img src="upload/images/<!!$sam.adpic!!>" alt="<!!$sam.adalt!!>"
width="100" height="100" border="0" class='picline'></a>
<a href="<!!$sam.adurl!!>" title="<!!$sam.adalt!!>"><!!$sam.adtitle|substrgb:'0':'20':''!!></a>
<!!/table_foreach!!>
4.包含文件,include
<!!include file="header.tpl"!!>
5.不解析,literal
<!!literal!!> 这里是js或css,模板不解析 <!!/literal!!>
6.条件判断,if,elseif,else
<!!if $name eq "Fred" and ($type eq '1' || $type eq '2')!!>
Welcome Sir.
<!!elseif $name eq "Wilma"!!>
Welcome Ma'am.
<!!else!!>
Welcome, whatever you are.
<!!/if!!>
"eq", "ne","neq", "gt", "lt", "lte", "le", "gte" "ge","is even","is odd",
"is not even","is not odd","not","mod","div by","even by","odd by","==","!=",">", "<","<=",">="
7:字符替换,replace
|replace:"1":"2" 1--将被替换的字符串 2--用来替换的文本
<!!$articleTitle|replace:"pear":"apple"!!>
8:去除Html标签,strip_tags
去除Html标签 去除在<和>之间的所有标签,包括<和>.
<!!$articleTitle|strip_tags!!>
8:字符截取,truncate,substrgb,mbstrutf8
截取|truncate:"1":"2":"3" 1--指定截取多少字符 2--截取后加在截取词后的字符串 3--检查是否截取到词的边界 Default(false)
<!!$articleTitle|truncate:30:"...":true!!>
<!!$articleTitle|substrgb:"0":"23":".."!!>
<!!$arr_story[$top18].rm_title|mbstrutf8:"0":"34":"..."!!>
<!!$arr_result[on
9:注释,Comments
注释
<!!* this is a comment *!!>
10:日期格式,date_format
日期格式
<!!$smarty.now|date_format!!>
<!!$smarty.now|date_format:"%Y/%m/%d"!!>
<!!$smarty.now|date_format:"%Y-%m-%d"!!>
%y:显示两位数字年份, 00 至 99
%Y:显示四位数字年份
%m:显示数字月份,01-31
%b:显示英文月份,简称
%B:显示英文月份,全称
%d 显示数字日份,01-31
%D 显示英文日份,简称3 个字母 Mon 到 Sun
11:日期下拉列表,html_select_date
日期下拉列表
<!!html_select_date prefix="StartDate" start_year="-5" end_year="+5" field_order="YMD" month_format="%m" display_days=false time="$time"!!>
time="2006-06-06" 可以给定输出想要的值
12:循环,foreach,foreachelse
选择性的section循环
from 需要循环的数组的名称
item 当前元素的变量名
key 当前关键字的变量名
name 访问foreache属性的foreach循环名
$smarty->assign("arr_result", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
<!!foreach name=outer item=contact from=$arr_result!!>
<!!foreach key=key item=item from=$contact!!>
<!!$key!!>: <!!$item!!>
<!!/foreach!!>
<!!/foreach!!>
<!!foreachelse!!> 在from变量没有值的时候被执行
13:下拉列表,html_options
输出下拉列表
name name of select group
values an array of values for dropdown
output an array of output for dropdown
selected the selected option element(s)
options an associative array of values and output
<select name=customer_id>
<!!html_options values=$cust_ids selected=$customer_id options=$cust_options output=$cust_names!!>
</select>
14:换行替换,nl2br
换行符替换成<br />
<!!$articleTitle|nl2br!!>
15:默认值,default
当变量为空或者未分配的时候,将由给定的默认值替代输出.
<!!$articleTitle|default:"no title"!!>
16:字符处理,capitalize,ucwords
将变量里的所有单词首字大写
<!!$articleTitle|capitalize!!>
<!!$articleTitle|ucwords!!>
17:字符串连接,cat
字符串连接 将cat里的值连接到给定的变量后面.
<!!$articleTitle|cat:" yesterday."!!>
18:字符处理,strtolower
将变量里的所有单词小写.
<!!$articleTitle|strtolower!!>
19:获取字符串,fetch
获取字符串
$str_html = $obj_smarty->fetch("index.html");
20:capture
capture函数的作用是收集模板输出的数据到一个变量里,而不是把它们输出到页面.
任何在 {capture name="foo"}和{/capture}之间的数据都被收到了由函数的名称属性指定的变量里($foo).
收集的信息可以用在特殊变量$smarty里.
例如capture.foo就收集了以上数据.如果函数没有名字属性,将使用"default".
每个{capture}都必须对应{/capture},也不能嵌套使用capture函数
{capture name=banner}
1
{/capture}
{capture name=banner2}
2
{/capture}
{if $smarty.capture.banner ne ""}
<tr>
<td>
{$smarty.capture.banner}
</td>
<td>
{$smarty.capture.banner2}
</td>
</tr>
{/if}
抓取数据存放在变量中 可以在一个页面中重复使用
21:include_php,php
include_php
在模板里加载php文件
php
可以直接使用php代码 相当于<?php ?>
<!!include_php file="phpinfo.php"!!>
<!!php!!>
include("phpinfo.php");
echo date("h:i:s");
<!!/php!!>
22:insert
使模板的一部分不被缓存
//demo.php
$int_cache_id = sprintf('%X', crc32("index.html"));
if( !$obj_smarty->is_cached('index.html', $int_cache_id) ) {
$obj_smarty->assign("str_date",date("h:i:s"));
}
$obj_smarty->display("index.html",$int_cache_id);
function insert_getBanner( $arrParams ) {
return $arrParams["lid"]."-andy-".$arrParams["sid"];
}
//index.html
<!!$str_date!!>
<!!insert name="getBanner" lid="1" sid="2" !!>
23:ldelim,rdelim
ldelim and rdelim are used for displaying the literal delimiter, in our case "{" or "}".
输出变量 不做解析
<!!ldelim!!>funcname<!!rdelim!!> is how functions look in Smarty!
OUTPUT:
<!!funcname!!> is how functions look in Smarty!
24:strip
去除<!!strip}<!!/strip!!>间的所有空格
25:{$smarty}保留变量
页面请求变量
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *}
{$smarty.get.page}
{* display the variable "page" from a form a form (POST) *}
{$smarty.post.page}
{* display the value of the cookie "username" *}
{$smarty.cookies.username}
{* display the server variable "SERVER_NAME" *}
{$smarty.server.SERVER_NAME}
{* display the system environment variable "PATH" *}
{$smarty.env.PATH}
{* display the php session variable "id" *}
{$smarty.session.id}
{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}
{$smarty.now}变量用于访问 当前时间戳.
可以用 date_format调节器格式化输出.
{* use the date_format modifier to show current date and time *}
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
{$smarty.const}
可以直接访问PHP常量.
{$smarty.const._MY_CONST_VAL}
{$smarty.template}
当前被处理的模板的名字
26:组合使用调节器 |
<!!$articleTitle!!>
<!!$articleTitle|upper|spacify!!>
<!!$articleTitle|lower|spacify|truncate!!>
<!!$articleTitle|lower|truncate:30|spacify!!>
<!!$articleTitle|lower|spacify|truncate:30:". . ."!!>
27:fetch
抓取数据
{* include some javas
{fetch file="/export/httpd/www.domain.com/docs/navbar.js"}
{* embed some weather text in your template from another web site *}
{fetch file="http://www.myweather.com/68502/"}
{* fetch a news headline file via ftp *}
{fetch file="ftp://user:password@ftp.domain.com/path/to/currentheadlines.txt"}
{* assign the fetched contents to a template variable *}
{fetch file="http://www.myweather.com/68502/" assign="weather"}
{if $weather ne ""}
{$weather}
{/if}
相关文章:

5G+XR:让视频增强技术在工业领域大有所为
据工业和信息化部统计显示,目前中国累计建成并开通5G基站142.5万个,基站总数今年有望突破200万个。自5G正式商用以来,凭借其高带宽、广连接、低延时等优势,5G应用的实践逐渐从最初的单一化业务触及至更广泛的行业应用场景中。其中…

IE的安全性设定增加“我的电脑”的安全性设定
HKEY_CURRE-NT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones\0,在右边窗口中找到DWORD值“Flags”,默认键值为十六进制的21(十进制33),双击“Flags”,在弹出的对话框中将它的键值改为“1”即可&#x…

F# 4.5提供Spans、Match!等特性
F# 4.5预览版现已发布,其中提供了一系列新特性,包括对.NET Core 2.1的新原生类型Span\u0026lt;T\u0026gt;的支持、新关键字Match!等。\\类型Span意在实现底层代码指针操作的安全性和可预测性,这可使得很多情况下不必再分配内存,进…

ecshop transport.js/run() error:undefined
在使用ECshop的AJAX(即:transport.js) IE有时候会出现:ReferenceError: process_request is not defined,FF则出现:transport.js/run() error:undefined,其实这完全和transport.js无关。那么问题出在哪里呢?…

为什么你不应该自行更新 Drupal 网站?
(译注:这篇文章主要还是针对于非专业人员及个人Drupal站长,对于专业的 Drupal 团队和公司而言 Drupal 的升级更新都有规范的操作流程,完全是家常便饭,不可能出现文中出现的这些情况。尽管如此,里面也还是有…

用友发布新一代企业智能商旅及费控服务平台
3月31日,“便捷商旅 智能费控—2022用友BIP|商旅及费控服务新品发布会”成功举行。作为新一代企业智能商旅及费控服务平台,用友BIP商旅及费控服务以“连接 高效 智能 合规”为核心价值理念,致力于让5000万报销人拥有极致的体验,让…

RNN,LSTM,GRU简单图解:
一篇经典的讲解RNN的,大部分网络图都来源于此:http://colah.github.io/posts/2015-08-Understanding-LSTMs/ 每一层每一时刻的输入输出:https://www.cnblogs.com/lovychen/p/9368390.html 带有权重标识的图:

ecshop模板smarty foreach详解 [ECshop]
{foreach},{foreachelse}{foreach} 用于像循环访问一个数字索引数组一样循环访问一个关联数组,与仅能访问数字索引数组的{section}不同,{foreach}的语法比 {section}的语法简单得多,但是作为一个折衷方案也仅能用于单个数组。每个{foreach}标…
自己动手,做一款抬头显示的「Todo Hud」
我用过好多款 TodoList 软件,但事情一多总还是丢三落四,原本计划好要做的事情总是安静地躺在某个角落,等我想起来要去扫一眼的时候,都已快「物是人非」。。。 要是能在桌面上实时显示 TodoList,那该多好!但…

微软语音扩展全球语言支持,发布160个新声音
导语:全世界有数千种语言,最具语言天赋的人也只能说数十种,普通人能够学会两三种语言已属不易。然而,在科技日新月异的今天,具备自然语言对话能力的AI已经能够掌握上百种语言,扩展人类自身能力,…

P4269 [USACO18FEB]Snow Boots G
思维题。 以地板为序构造链表,再排序,然后删除走不过去的地面。 删除的时候顺便维护最大的跨度,以此判断可行性。 总的来说利用了答案的单调性。 #include <cstdio> #include <cstring> #include <iostream> #include <…

GPT-3:现实版的“贾维斯”?还是真「人工」智能?
整理 | 章雨铭 责编 | 屠敏出品 | CSDN(ID:CSDNnews)GPT-3(Generative Pre-trained Transformer 3)自2020年推出以来就备受热议,它是一种由OpenAI开发的AI工具。发布的两年来,外媒The Verg…

SVN更换修改用户名
如果装了TortoiseSVN: Settings -> Saved Data -> Authentication Data -> clear。即可清除保存的上个用户登录信息;当再次用到svn时,会提示输入用户名密码,输入新的用户名密码即可。 或者,手动删除下面目录下…

启用CORS实现Ajax跨域请求
2019独角兽企业重金招聘Python工程师标准>>> 应用场景:想从a.com请求b.com上的资源,由于同源策略不允许请求。 解决办法:在请求的php文件中加入 header("Access-Control-Allow-Origin: http://b.com"); 这种比较安全&am…

Python机器学习实践指南pdf (中文版带书签)、原书代码、数据集
Python机器学习实践指南 目 录 第1章Python机器学习的生态系统 1 1.1 数据科学/机器学习的工作 流程 2 1.1.1 获取 2 1.1.2 检查和探索 2 1.1.3 清理和准备 3 1.1.4 建模…

虚拟机安装CentOS以及SecureCRT设置【完美无错版】
一、CentOS简介CentOS是Linux的发行版之一,它安全、稳定、高效,是我最喜欢的Linux发行版之一。CentOS根据Red Hat Enterprise Linux开放源代码编译而成,与RedHat Linux并没有什么本质上的差别。但Red Hat Enterprise Linux是商业软件…

Python 实现机器学习前后端页面的交互
作者 | 俊欣来源丨关于数据分析与可视化对于机器学习爱好者而言,很多时候我们需要将建好的模型部署在线上,实现前后端的交互,今天小编就通过Flask以及Streamlit这两个框架实现机器学习模型的前后端交互。模型的建立首先是模型的建立ÿ…

webpack入门(二)what is webpack
webpack is a module bundler.webpack是一个模块打包工具,为了解决上篇一提到的各种模块加载或者转换的问题。 webpack takes modules with dependencies and generates static assets representing those modules. webpack以依赖模块和生成 静态的资源来代表这些模…

vSAN读者交流之1-要为不同时间的服务器选择合适的系统版本
近期在我的虚拟化群中,有两个问题比较典型:在比较老的服务器安装新的VMware ESXi 6.7或vCenter Server 6.7出错。在比较新的服务器安装比较旧的ESXi版本5.5出错。因为每个人的实验环境不同、条件不同,用不同的服务器做实验,或者为…

ecshop中ajax的调用原理
1:首先ecshop是如何定义ajax对象的。ecshop中的ajax对象是在js/transport.js文件中定义的。里面是ajax对象文件。声明了一个var Ajax Transport;对象和一个方法Ajax.call Transport.run;2:ecshop中ajax可以使用两种方式传递数据.一种是get方式,一种是p…

IOS7原生API进行二维码条形码的扫描
2019独角兽企业重金招聘Python工程师标准>>> //需要真机 #import "ViewController.h" #import <AVFoundation/AVFoundation.h>interface ViewController ()<AVCaptureMetadataOutputObjectsDelegate>//用于处理采集信息的代理 {AVCaptureSess…

元宇宙中可跨语种交流,Meta 发布新语音模型,支持128种语言无障碍对话
编译 | 禾木木 出品 | AI科技大本营(ID:rgznai100) 语言交流是人类互动一种自然的方式,随着语音技术的发展,我们可以与设备以及未来的虚拟世界进行互动,由此虚拟体验将于我们的现实世界融为一体。 然而,…

sql server几种读写分离方案的比较
原文:sql server几种读写分离方案的比较在生产环境中我们经常会遇到这种情况: 前端的oltp业务很繁忙,但是需要对这些运营数据进行olap,为了不影响前端正常业务,所以需要将数据库进行读写分离。 这里我将几种可以用来进行读写分离的…

Jquery和javascript常用技巧
var objSel document.getElementById("selOp"); //这是获取值 alert("当前值: " objSel.value); //这是获取文本 alert("当前文本: " objSel.options(objSel.selectedIndex).text);…

LeetCode刷题-1
数组-1.两数之和题目描述题目样例Java方法:暴力枚举思路及算法代码执行结果复杂度Java方法:哈希表思路及算法代码执行结果复杂度题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数…

测试驱动开发与行为驱动开发中的测试先行方法
Gil Zilberfeld将在 Agile Practitioners会议上举办小型研讨会,讨论测试先行(test first)方法,测试驱动开发(TDD)和行为驱动开发(BDD)的基础。 \\\ Test-First是一个很优秀的工具。它…

在jupyter notebook中同时安装python2和python3
环境 win10 已安装anaconda3 How 1.安装python27> conda create -n py27 python2.72. conda install --prefixD:\pyenv\py27 ipykernel(python27 指定路径:D:\pyenv\py27)3. activate py27(查看 conda info --envs)4. python -m ipykernel install --user5.启动j…

简化代码的微小修改
可选参数和命名实参 可选参数如果操作需要多个值,而有些值在每次调用的时候又相同,这时可以使用可选参数声明可选参数并在调用时省略它们#region 13-1声明包含可选参数的方法并调用static void Dump(int x, int y 20, int z 30)//声明包含了可选参数的…

windows版本下使用xdebug
下载xdebug: http://www.xdebug.org/download.php 这个版本: http://www.xdebug.org/files/php_xdebug-2.2.0-5.3-vc9.dll拷贝到php的ext目录 配置php.ini extensionphp_xdebug-2.2.0-5.3-vc9.dll;xdebug.profiler_enable1;xdebug.profiler_output_dir"E:\PHPn…

LeetCode刷题-2
数组-26.删除有序数组中的重复项题目描述题目样例Java方法:双指针思路及算法代码执行结果复杂度题目描述 给你一个有序数组 nums ,请你原地删除重复出现的元素,使每个元素只出现一次 ,返回删除后数组的新长度。不要使用额外的数组…