Re: [SMARTY] my first plugin! :)
| From: | Jason Sweat | Date: | Wed, 05 Jun 2002 03:41:12 +0000 |
| Subject: | Re: [SMARTY] my first plugin! :) | ||
| References: | 1 2 3 4 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4598@lists.php.net to get a copy of this message | ||
Using your technique, and this file:
<?php
require_once('Smarty.class.php');
preg_match('/.*\/([^\/]+).php/', $_SERVER['SCRIPT_NAME'], $foo);
$t = new Smarty;
$t->display($foo[1].'.tpl');
?>
You would never have to write a line of PHP again! Just make a symbolic
link to this file as email.php or login.php and it will call email.tpl or
login.tpl automatically ;-P
On a more serious note, I have generally worked on smaller projects for our
corporate intranet, and have generally been the only php coder/html
developer on the project. None the less, I try to live by these two rules:
1) my php files have no HTML in them anywhere
2) my templates have no logic that does not affect display in them
and I have of course found Smarty to be a fantastic tool for achieving this
separation of presentation from business logic.
I tried to capture the heart of this in my tutorial published at
http://www.zend.com/zend/tut/tutsweatpart2.php
. Reading this may give you a
feel for how many of the people on this list tend to use Smarty.
Regards,
Jason
----- Original Message -----
From: "Monte Ohrt" <monte@ispi.net>
To: "Rasmus Schultz" <mindplay@mindplay.dk>
Cc: "Smarty List" <smarty-general@lists.php.net>
Sent: Tuesday, June 04, 2002 8:46 PM
Subject: Re: [SMARTY] my first plugin! :)
> 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
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>