Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
tables with summary line

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
SlowFox
Smarty Regular


Joined: 02 Oct 2006
Posts: 40

PostPosted: Wed Apr 11, 2012 8:42 am    Post subject: tables with summary line Reply with quote

Given is a template like this:
Code:

<table>

<tfoot>
<tr>
  <td>Avg.</td>
  <td>{$average}</td>
</tr>
</tfoot>

<tbody>
{foreach $data as $item}
<tr>
  <td>{$item->Name()}</td>
  <td>{$item->Value()}</td>
</tr>
{/foreach}
</tbody>

</table>


The problem is to compute $average. Of course this could be done by the application, but the real-world example is more complicated and - in my opinion - it is not the job of the application logic to calculate presentation details (and nobody knows which figures people want to see next in their reports anyway).

Now of course Smarty can easily calculate $average, but due to the weird HTML-sequence "footer before body" the result is needed before it is available. And running
Code:

{foreach $data as $item}{/foreach}

twice does not seem to be good practice either.

Is there something like the way to go in order to swap footer and body between template and actual output?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP