Re: [PHPLIB-DEV] cvs commit From: Kirill Maximov (kir <email protected>)
Date: 03/30/00

Kristian KÃhntopp wrote:

> kir wrote:
> > - More story about templates. Now Template class from template.inc
> > supports conditional blocks:
> > <!-- BEGIN var IF {expression} --> {another_var} html code
> > <!-- END var -->
>
> Argh! Please no! Please remove this!
>
> NO CODE IN TEMPLATES! NO CONDITIONS IN TEMPLATES! NO LOGIC IN TEMPLATES!
>
> If you want to have conditional replacement of {PLACEHOLDER},
> set_var("PLACEHOLDER", ""); Anything programmatic does not
> belong into a template, but into your code.
>

  Well, I have the situation when i want to output something about 10 fields
(address, phone, email, fax, etc)
  in some table. But I don't want to output header for field when the field is
empty:

  <TR BGCOLOR="white" ALIGN=LEFT><TH>Name</TH><TD>{NAME}</TD>
  <TR BGCOLOR="white" ALIGN=LEFT><TH>Email</TH><TD><FONT
color="red">{EMAIL}</FONT></TD>
  <TR BGCOLOR="white" ALIGN=LEFT><TH>Fax</TH><TD>{FAX}</TD>

  It gives bad result when EMAIL empty. What I did is:

      <TR BGCOLOR="white" ALIGN=LEFT><TH>Name</TH><TD>{NAME}</TD>
<BEGIN email_if IF {email_test} -->
      <TR BGCOLOR="white" ALIGN=LEFT><TH>Email</TH><TD><FONT
color="red">{EMAIL}</FONT></TD>
<END email_if -->
<BEGIN fax_if IF {fax_test} -->
      <TR BGCOLOR="white" ALIGN=LEFT><TH>Fax</TH><TD>{FAX}</TD>
<END fax_if -->

Well, now i don't have to put line
      <TR BGCOLOR="white" ALIGN=LEFT><TH>Email</TH><TD><FONT
color="red">{EMAIL}</FONT></TD>
into separate file or hard code this line in my PHP script and replace it with
{TABLE_EMAIL_LINE} in template.

  I'm quite sure that the thing i did it quite useful for such situations.
  Comments ?

  Regards,
  KIR

--
-----  -----  -----  -----  -----  -----  -----  -----
Kirill Maximov                     maximov <email protected>
Astrive, Inc.                   http://www.astrive.com

- PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>. To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in the body, not the subject, of your message.