简体   繁体   中英

Working With Tables in the Smarty Template System

Here's a copy of my current code:

    <tbody>
      {foreach key=num item=referral from=$referrals}
      {if $referral.commission != '$0.00 USD'}
  <tr>
    <td>{$referral.date}</td>
    <td>{$referral.service}</td>
    <td>{$referral.amountdesc}</td>
    <td>{$referral.commission}</td>
    <td>{$referral.status}</td>
  </tr>
      {/if}
      {foreachelse}
        <tr>
            <td colspan="6">{$LANG.norecordsfound}</td>
        </tr>
      {/foreach}
    </tbody>

The table basically shows affiliate commissions that have been earned by affiliates. However, if the commission about is $0.00 USD , it doesn't show that row since no money was earned from that referral. But I've run into 2 different problems:

  1. If the affiliate has only referred people that they've received $0.00 commission from, this part of the table doesn't show. Instead it should be showing the language from {$LANG.norecordsfound} to let them know there's no commissions earned yet. Instead it's just show up blank.

  2. My table in paginated so that 10 records show per page. The problem is that if 3 of those commissions earned $0.00, it just shows 7 records on that page. I would prefer to remove pagination and just set $itemlimit to 9999 but I'm not sure how to do that.

Any help with this would be greatly appreciated.

Maybe you can try it this way instead so that it doesn't show a blank.

 <tbody>
   {foreach key=num item=referral from=$referrals}
    {if $referral.commission != '$0.00 USD'}
      <tr>
        <td>{$referral.date}</td>
        <td>{$referral.service}</td>
        <td>{$referral.amountdesc}</td>
        <td>{$referral.commission}</td>
        <td>{$referral.status}</td>
      </tr>
     {else}
         <tr>
           <td colspan="6">{$LANG.norecordsfound}</td>
         </tr>
     {/if}
     {/foreach}
</tbody>

For your 2nd issue, you might have to restructure how you do your table. What happens if you have less than 10 items from the start?

Since I can't see how you code your pagination, maybe you can assign the number of records in your php code and then check it in smarty in your table code.

For example if $itemlimit shows the number of records, then maybe you can do something like this.

{if $itemlimit > 10}
    {* show pagination or however you want to handle it *}
{/if}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM