Reputation: 8113
I was wandering.. If, say, I have to build a menu, or say, a group of specs sheets based on an array of product data.. In other words, if I have to render an array, what is better (from a performance point of view):
a. build all the html in php (say in a controller) and pass to smarty the variable where I saved the html
b. do nothing in php, pass the array to smarty and build the relevant html within the template?
Upvotes: 0
Views: 45
Reputation: 97898
Smarty templates are compiled into PHP code the first time they are processed, so unless you are doing some particularly exotic processing which is hard to express in Smarty syntax, the chances are the performance will be very similar.
The question also sounds a lot like "premature optimisation": you are assuming in advance that something might be a performance issue, and spending energy "optimising" it before you have any measurable outcome. This energy would be better saved for later when you actually have some performance to measure, and can find which parts of the code can give you the biggest improvement.
Whether it is your choice or that of the application you are using, the idea of a templating language like Smarty is that it contains all your display logic, so moving display logic into the "controller" (which would presumably then also be a "view" in the MVC way of thinking) defeats the point of the separation.
If you really hate Smarty, you could presumably write your own "view" layer, which pre-processed all the output into HTML, and passed a single variable to the Smarty template, but I'm not sure that's what you're after.
Upvotes: 1