Re: [SMARTY] my first plugin! :)

From: Date: Wed, 05 Jun 2002 01:46:45 +0000
Subject: Re: [SMARTY] my first plugin! :)
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4593@lists.php.net to get a copy of this message
Rasmus Schultz wrote:
On another note, burying sql queries in the templates is a bad idea, IMHO. It works against the basic principals of separating business logic from display logic.
dumping a few headlines from a news table hardly constitutes "business logic", does it? ;) ... in general, I see your point - I would not use this plugin for any major functionality, but it is handy if you want to quickly pull a headline from a news table. And if you want a bit more separation, you can always drop your SQL query in a config file...
You want to be able to include this template arbitrarily without the dependency of your application supplying the variables ahead of time, right? Just include it and wala, it works! A situation that Smarty coins as "Componentized Templates." Read that portion of the manual to see how to do this without mixing the logic in your template files. Hint: {include_php} is your friend! We do this with a site navigation bar. The links in the navigation are generated from a database, and any time we {include file="topnav.tpl"} it just works :-) http://www.phpinsider.com/php/code/Smarty/docs/tips.componentized.templates.html
You really want to dig through templates to adjust sql queries?
so allow me to turn your question around: do you really want to dig through lengthy PHP scripts to adjust a tiny SQL query?
As opposed to handling it in a template? Absolutely. Be sure to organize your applications so they are managable, which should be common knowledge ;-)
Do the sql stuff in your application, let the templates focus on the display of your content.
but that's what I'm doing - it just so happens some of my content (i.e. some news headlines and stuff) is stored in a database. now why should I have to code anything additional in order to pull out those data? with this plugin, I don't have to. admit it, it's great, and you love it! ;)
I've been there many times, tried it many times, and there just isn't any good in doing it that way. You are free to do it, but I certainly don't recommend it as a programming practice. Monte

« previous php.smarty.general (#4593) next »