in reply to Templating algorithm - pass in variables vs callback?

As others have mentioned, Template Toolkit lets you have it both ways. The main advantage though of pre-calculating answers is that you often know better than the template how to get the data efficiently. For example, you might use one large SQL query that joins several tables to get all the data you need at once, rather than using multiple queries called from the template. For your example with the thousands of iterations, the solution would be to only calculate the ones you need before running the template, rather than doing all of them.

The downside of this is that it tightly couples your code to the template.

  • Comment on Re: Templating algorithm - pass in variables vs callback?