PHP头条
热点:

php-smarty模板使用教程(三)自定义函数与配置文件


五、自定义函数 1、assign  {assign var=“var” value=“value”} 创建一个模板变量 Var:变量名 Value:变量值   smarty
  2、counter {counter start=0 skip=2 print=false}  计数器 Start:开始的值 Skip:步长 Print:本次是否打印 {counter}
  {counter}
   
  3、cycle   轮转功能  
  4、debug {debug}  打开调试窗口 (观察所有模板变量)  
  5、eval {eval var=#ErrorState# assign="state_error"}  计算变量的值  
  6、fetch {fetch file=“file” assign=“var”} Fetch表示获取某个文件的内容 File:文件名 Assign:将结果保存到指定的变量中  
  7、html_image {html_image file="pumpkin.jpg"}  输出一个img File:要输出的图像  
  8、html_table {html_table loop=$data cols=4 table_attr='border="0"'}  用表格table显示数组的值 Loop:要循环的数组 Cols:每行显示多少个 Table_attr:表格属性 Html_table用于显示简单数据(一维数组)  
  9、html_checkboxes {html_checkboxes  values=$cust_ids  checked=$customer_id  output=$cust_names  separator=""}  表示在页面中输出一组复选框 Values:值的数组 Checked:被选中项的值的数组 Output:显示的文本的数组 Separator:分隔符(每个复选框之间的分隔符) 一组复选框必须设置values和output参数 Php代码: $text=array('足球','电影','彩票','打麻将','美女'); $smarty->assign('text',$text); $value=array(1,2,3,4,5); $smarty->assign('value',$value); $check=array(2,5); $smarty->assign('check',$check); 模板代码: {html_checkboxes name='love' values=$value output=$text checked=$check separator=' '}   10、html_options   {html_options values=$cust_ids selected=$customer_id output=$cust_names}    在页面中输出一组下拉列表选项 Values:(option values  )值的数组 Selected:被选中项的值 Output:显示的文本的数组 Php代码: $opText=array('北京','上海','美国'); $smarty->assign('opText',$opText); $opValue=array(1,2,3); $smarty->assign('opValue',$opValue); $smarty->assign('selected',2); 模板代码: {html_options values=$opValue output=$opText selected=$selected} 11、html_radios {html_radios values=$cust_ids checked=$customer_id output=$cust_names separator=""}  在页面中输出一组单选按钮 Values:值的数组 Checked:被选中项的值 Output:显示的文本的数组 Separator:分隔符 Php代码: $raText=array('男','女','保密'); $smarty->assign('raText',$raText); $raValue=array(1,2,3); $smarty->assign('raValue',$raValue); $smarty->assign('checked',3); 模板代码: {html_radios name='sex'  values=$raValue output=$raText checked=$checked separator=' '}     六、smarty中使用配置文件   配置文件有利于设计者管理文件中的模板全局变量。最简单的例子就是模板色彩变量。一般情况下你如果想改变一个程序的外观色彩,你就必须通过去更改每一个文件的颜色变量。如果有这个配置文件的话,色彩变量就可以保存在一个地方,只要改变这个配置文件就可以实现你色彩的更新。 配置文件的格式: [color] bgColor = #000000  tableBgColor = #000000  fontBgColor = #00ff00  …… 引用配置文件的格式: {config load}   
    smarty
    smarty 自定义函数

www.phpzy.comtrue/phpkj/10598.htmlTechArticlephp-smarty模板使用教程(三)自定义函数与配置文件 五、自定义函数1、assign{assignvar=“var”value=“value”}创建一个模板变量Var:变量名Value:变量值 2、counter{counterstart=0skip=2print=false}计数器...

相关文章

相关频道:

PHP之友评论

今天推荐