NYCPHP Meetup

NYPHP.org

[nycphp-talk] Smarty Templates

billy reisinger billy.reisinger at gmail.com
Wed Nov 2 15:11:52 EST 2005


Using HTML_Template_ITX (from PEAR), the same snippet would look like:

<!-- BEGIN FORM_ERROR -->
<tr><td>&nbsp;</td><td>{FORM_ERROR_MESSAGE}</td></tr>
<!-- END FORM_ERROR -->

<tr><td class="label">
<label for="lastname">Last name</label>
</td>
<td>{FORM_LASTNAME_HTML</td></tr>

The advantage being that the HTML guy would already know what the <!-- -->
tag does. THe rest of it doesn't look as confusing, either, IMHO. I really
prefer HTML_Template_ITX over Smarty. I agree with you about making the php
code cleaner, it really does. Here's what the php for this block would look
like:

if ($form.lastname.error) {
$template->setCurrentBlock("FORM_ERROR");
$template->setVariable("FORM_ERROR_MESSAGE", $form.lastname.error);
$template->parseCurrentBlock();
}
$template->setVariable("FORM_LASTNAME_HTML", $form.lastname.html);

My 2 cents :-)


--
Billy Reisinger
billy.reisinger at gmail.com
410.736.0148


On 11/2/05, David Mintz <dmintz at davidmintz.org> wrote:
>
>
> I've noticed that if you use e.g. HTML_QuickForm (a Good Thing, IMHO) then
> you eventually find yourself almost coerced into getting involved in
> Smarty (or some other template engine), because QF's default renderer is
> just adequate for the simplest of display tasks, and customizing it
> heavily is really tedious. OTOH your Smarty templates end up looking like
>
> {if $form.lastname.error}
> <tr><td>&nbsp;</td><td>{$form.lastname.error}</td></tr>
> {/if}
> <tr><td class="label">
> <label for="lastname">Last name</label>
> </td>
> <td>{$form.lastname.html}</td></tr>
>
> which about as ugly as the other alternatives. Still, I think it's worth
> it. I have taken to sticking the form initialization work into the same
> classes that do the db access work. The result is that the PHP scripts
> that control the flow end up being short and sweet.
>
>
> ---
> David Mintz
> http://davidmintz.org/
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20051102/696f4f68/attachment.html>


More information about the talk mailing list