Smarty : how to alternate colors in a template  Bottom

  • alternate with two colors

    if you wan't to alternate color with an odd and even color

    you can do it like this

    Code

    <!--[foreach item='field' from=$fields]-->
      ...
          <!--[cycle values="pn-odd,pn-even" assign='class']-->
            <tr class="<!--[$class]-->">
            ..
     <!--[/foreach]-->

    taken from "users_admin_viewtempuserdetails.htm"

    or like this ( it's a beat heavy)

    Code

    <!--[counter start=0 skip=1 assign="row" ]-->
        <!--[section name=users loop=$users]-->
        <!--[counter assign="row" ]-->
        <!--[ if $row is not odd ]-->
            <tr bgcolor2"]-->;">
        <!--[ else ]-->  
        <tr>
        <!--[ /if ]-->  
     ...
     <!--[/section]-->

    taken from the old memberslist_user_view.htm

    alternate with n colors

    By using the sample from the member list, you can't alternate on n colors by using

    Code

    {* 0=even, 1=even, 2=even, 3=odd, 4=odd, 5=odd, etc. *}
     <!--[if $var is even by 3 ]-->
      ...
     <!--[/if]-->


    http://www.smarty.net/manual/en/language.function.if.php



    edited by: mumuri, Jan 11, 2009 - 07:16 AM

This list is based on users active over the last 60 minutes.