Smarty最简单实现列表奇偶变色的方法

本文实例讲述了Smarty最简单实现列表奇偶变色的方法。分享给大家供大家参考。具体如下:

最近在换模板的过程中遇到过一个问题:列表页隔行换色,本来想用程序实现的,但在网上发现smarty模板中有一个很方便的方法,特分享一下:

{section name=cat loop=$list}
  <tr bgcolor="{cycle values="#FFFFFF,#CCCCCC"}">
   <td>{$list[cat].id}</td>
  </tr>
{/section}

希望本文所述对大家的smarty模板程序设计有所帮助。

(0)

相关推荐

  • CodeIgniter中使用Smarty3基本配置

    一.创建Smarty类库 1.将smarty的libs文件复制到libraries下(这里我重命名为smarty) 2.新建Cismarty.php文件.(符合文件规范,文件名的首字母和class名的首字母大写,但是控制器引用加载时,类名/文件名不需要大写) Cismarty.php <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require(APPPATH . 'libraries/smart

  • smarty学习笔记之常见代码段用法总结

    本文实例讲述了smarty常见代码段.分享给大家供大家参考,具体如下: 1. <select > {html_options values=$cust_ids selected=$customer_id output=$cust_names} </select> 说明:生成下拉菜单.values=一个数组,数组元素为列表值 selected=一个值,这个是默认的列 表值 output=一个数组,数组元素为显示的列表值 {html_checkboxes values=$cust_id

  • PHP文件缓存smarty模板应用实例分析

    本文实例分析了PHP文件缓存smarty模板应用.分享给大家供大家参考,具体如下: 一.使用缓存 要开启smarty的缓存,只需将caching设为true,并指定cache_dir即可. 使用cache_lefetime指定缓存生存时间,单位为秒 要对相同页面生成多个不同的缓存,在display或fetch中加入第二参数cache_id,如: $smarty->display('index.tpl',$my_cache_id); 此特性可用于对不同的$_GET进行不同的缓存   二.清除缓存

  • php实现smarty模板无限极分类的方法

    本文实例讲述了php实现smarty模板无限极分类的方法.分享给大家供大家参考,具体如下: <?php $conn = mysql_connect("localhost","admin","admin"); mysql_select_db("people_shop",$conn); mysql_query("SET NAMES 'UTF-8'"); $class_arr=array(); $sql =

  • Smarty使用自定义资源的方法

    本文实例讲述了Smarty使用自定义资源的方法.分享给大家供大家参考.具体如下: <?php // put these function somewhere in your application function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj) { // do database call here to fetch your template, // populating $tpl_source $sq

  • Ajax+smarty技术实现无刷新分页

    这里运用Smarty模板,更简单 本文主要的技术:AJAX,PHP,Smarty,另外自己封装了一个很简单的类 类: (function(){ function $(id) { return document.getElementById(id); } $.init=function() { try{return new XMLHttpRequest();}catch(e){}; try{return new ActiveXObject('Microsoft.XMLHTTP');}catch(e

  • Smarty foreach控制循环次数的一些方法

    1.在 smarty 中数组是经常会用到的,循环遍历数组用 section 或者 foreach ,如何得到数组长度或者判断一个数组个数呢?可以用{$array| count} 来试试. 2. 复制代码 代码如下: {foreach from=$variable key=key name=name iteam=value} {$variable|@count}     // 获取数组长度 {$smarty.foreach.loop.index}    // 获取当前循环数组元素下标,以0开始 {

  • Codeigniter中集成smarty和adodb的方法

    本文实例讲述了Codeigniter中集成smarty和adodb的方法.分享给大家供大家参考,具体如下: 在CodeIgniter中要写自己的库,就需要写两个文件,一个是在application/init下面的init_myclass.php文件(如果没有init目录,自己创建).另外一个就是在application/libraries目录下创建myclass.php文件. 这里myclass是你的类名.一些规则大家看手册就好了,我这里直接就说步骤了. 1)在application/libra

  • smarty简单应用实例

    本文讲述了smarty简单应用实例.分享给大家供大家参考,具体如下: <?php require 'smarty/libs/Smarty.class.php'; $smarty = new Smarty; $smarty->template_dir="smarty/templates/templates"; $smarty->compile_dir="smarty/templates/templates_c"; $smarty->config

  • Zend Framework实现Zend_View集成Smarty模板系统的方法

    本文实例讲述了Zend Framework实现Zend_View集成Smarty模板系统的方法.分享给大家供大家参考,具体如下: Zend_View抽象出了Zend_View_Interface,可以让我们集成不同的视图解决方案,例如可以集成smarty.要在zend中使用其他视图系统作为视图,只要实现Zend_View_Interface接口即可. Zend_View_Interface的接口定义: <?php /** * Interface class for Zend_View compa

  • smarty中常用方法实例总结

    本文实例总结了smarty中常用方法.分享给大家供大家参考.具体如下: 1. Smarty中foreach的index.iteration的使用 .index包含当前数组索引,从零开始. index示例 {* The header block is output every five rows *} {* 每五行输出一次头部区块 *} <table> {foreach from=$items key=myId item=i name=foo} {if $smarty.foreach.foo.i

  • yii,CI,yaf框架+smarty模板使用方法

    本文实例讲述了yii,CI,yaf框架+smarty模板使用方法.分享给大家供大家参考,具体如下: 最近折腾了框架的性能测试,其中需要测试各个模板跟smarty配合的性能,所以折腾了一桶,现总结一下.之前已经写过kohana框架+smarty模板,这里不再重复了. 一.yii框架+smarty模板 yii是覆盖了viewRenderer组件. 1.1,下载yii框架并解压,下载smarty框架并解压,将smarty/libs文件夹拷到yii框架application/protected/vend

  • smarty高级特性之过滤器的使用方法

    本文实例分析了smarty高级特性之过滤器的使用方法.分享给大家供大家参考,具体如下: 高级特性中过滤器的使用 1.预过滤器 function remove_dw_comments($tpl_source, &$smarty) { return preg_replace("/<!--#.*-->/U","",$tpl_source); //去除原tpl文件中的注释,使其在编译后的文件中不显示 } //注册预过滤器 $smarty->regi

  • smarty高级特性之对象的使用方法

    本文实例讲述了smarty高级特性之对象的使用方法.分享给大家供大家参考,具体如下: <?php include_once('smarty.inc.php'); class Dog{ public $name; public function sayHello(){ echo 'hello'; } } $dog1=new Dog(); $dog1->name="first dog"; $smarty->assign("dog",$dog1); $s

随机推荐