Smarty模板技术-自定义函数-1

来源:互联网 发布:皇室战争电磁炮数据 编辑:程序博客网 时间:2024/04/30 11:47

1.PHP文件内容

注:本文代码均出自瓢城Web俱乐部李炎恢老师Smarty教学视频,仅供学习和研究使用
   <?php      require_once '../smarty.inc.php';      global $smarty;      $smarty->assign('title' , 'Smarty模板引擎之自定义函数');      $smarty->assign('table' , array(1,2,3,4,5,6));      $smarty->assign('x' ,100);      $smarty->assign('y',3);    $smarty->assign('opt' , array('a'=>1 , 'b'=>2 , 'c'=>3 , 'd'=>4));    $smarty->assign('id' , 'c');      $smarty->display('index.html');

1.模板文件内容

<!doctype html><html>    <head>    <meta charset="utf-8">    <title>{$title}</title>     </head>    <body>    {* 模板自定义属性 *}        {* assign 用于在模板被执行时,为变量赋值 *}            {assign var='mail' value='173000950@qq.com'}            mail:{$mail} <br />        {* counter 用于输出一个计数过程 *}            {counter start=5 skip=2 direction=down }            |            {counter print=false}            |            {counter assign=c}            {$c}        {* cycle   轮换使用一组数据 *}            <p style="background:{cycle values='red,green'}">1</p>            <p style="background:{cycle values='red,green'}">1</p>        {* debug 可以查看模板各个信息 *}            {debug}        {* eval  用于显示普通变量和配置变量 *}            {eval var=$title assign=c}            {$c}        {* fetch 引入其他文件的原代码 *}            {fetch file='http://www.onlycat.cc'}        {* html_image 创建一张图片 *}            {html_image file="http://www.onlycat.cc/img/search.png" alt="来自猫先生的图" width="100px" height="100px" href="http://www.onlycat.cc"}        {* html_table 显示表格 *}            {html_table loop=$table cols=3}        {* math 进行模板计算 *}            {math equation=$x*$y}          {*  mailto 创建电子邮件链接 *}            {mailto address="173000950@qq.com" text='onlycat'}        {* textformat 文字格式化 *}            {textformat indent=20}            onlycat            {/textformat}        {* html_checkboxes 批量显示复选框 *}            {html_checkboxes options=$opt  checked=$id}        {* html_radios 批量显示单选择框 *}            {html_radios options=$opt  checked=$id}        {* html_options 下拉菜单 *}            <select>            {html_options options=$opt  selected=$id}            </select>        {* html_select_date 显示日期的下拉列表 *}            {html_select_date month_format='%m' field_order=YMD start_year=1999 }        {* html_select_time 显示时间的下拉列表 *}            {html_select_time}    </body></html>
0 0
原创粉丝点击