Date: 07/21/00
- Next message: Öܺ: "[phplib] support needed"
- Previous message: Padraic Renaghan: "Re: [phplib] Conditional blocks"
- In reply to: Padraic Renaghan: "Re: [phplib] Conditional blocks"
- Next in thread: Zakaria: "Re: [phplib] Conditional blocks"
- Reply: Zakaria: "Re: [phplib] Conditional blocks"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
For those that are interested in this question, I happen to think that the
right thing to do is a hybrid of these approaches. PHP *is* a templating
language in the first place. Kristian once pointed this out to me, and we
discussed how funny it is to implemented a templating language within PHP.
Therefore, I think the right thing to do is to use templates that are
actual PHP include files, and which can be include()ed at will. These
template files should not mix PHP and HTML, they should use a clean
template-like interface for fetching it. I have built a library that allows
you to do this in an object-oriented way. So, although you can have more
complex PHP if you want, usually you just do things like:
<? $this->show( "foobar" ) ?>
Since show() is a function call, you can have it do some basic logic and
text processing for you. Further, if you want, you can also do something
contsructs like this:
<? if( $this->foo ): ?>
<? $this->show( "bar" ) ?>
<? endif; ?>
I have built a relatively large site using this model, and I have found
that my HTML designers have had no trouble adapting. After all, to them the
<? ?> is just a normal-looking HTML tag. It even seems to work with GUI
editors like Dreamweaver.
I call the package EnzymeTemplates, and you can find out more at
http://enzyme.sourceforge.net
Sorry for the plug, hope you find it useful. I have been playing with
porting phpSlash to this system, but I'll save the announcement for the
appropriate list.
Eric
At 11:28 PM 7/20/00, Padraic Renaghan wrote:
>* Zakaria <zak_mail <email protected>> [Jul 21 9:53am]:
> > I second the motion.
>
>I'm going to disagree here. I believe that ALL php code belongs in php
>files and all HTML belongs in templates. No exceptions. As the highest
>court in my land might say, "php in templates starts you on a
>slipperly slope".
>
> > Another use of having conditional in template is to separate the content
> > and the formatting of HTML. That way you don't have to change
> > the script if you want to change the template (big changes).
> >
> > For example you have template like this
> > {ERROR_MSG}
> > <table>... data ...</table>
> >
> > which ERROR_MSG is the message if there is an error or empty if there is
> > no error. It's fine and dandy till your boss said he want the error message
> > in Bold and red.
> >
> > So you have two choise you could change it in the code or you could add it
> > in the template. Let just say you change the template to become like this:
> > <b class="red_error">{ERROR_MSG}</b>
> > <table>... data ...</table>
>
>Not necessarily. I do this very same thing with every site I create.
>Instead of {ERROR_MSG} being set via a set_var, conditionally decide
>whether or not to parse it as its OWN TEMPLATE. Something like:
>
>$tpl->set_unknowns("remove");
>$tpl->set_file(array(error_msg => "error_msg.tpl"));
>
>if (!empty($myError)) {
> $tpl->set_var("ERROR_MSG_TXT", $myError);
> $tpl->parse("ERROR_MSG", "error_msg");
>}
>
>error_msg.tpl would be:
><b class="red_error">{ERROR_MSG_TXT}</b>
>
>while the main body template would be:
>...
>{ERROR_MSG}
>... main page content ...
>
>You can then easily change the contents of error_msg.tpl when your
>boss wants the stop sign icon to the error message display. No need to
>touch any PHP code.
>
>If you didn't have unkowns set to remove, you could just set_var
>ERROR_MSG to "" if you like.
>
>--
>Padraic Renaghan /pad-rik ren-a-han/
>padraic <email protected>
>ICQ# 9437815 AOL IM: PadraicRenaghan
>http://renaghan.com/pcr/
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: phplib-unsubscribe <email protected>
>For additional commands, e-mail: phplib-help <email protected>
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>
- Next message: Öܺ: "[phplib] support needed"
- Previous message: Padraic Renaghan: "Re: [phplib] Conditional blocks"
- In reply to: Padraic Renaghan: "Re: [phplib] Conditional blocks"
- Next in thread: Zakaria: "Re: [phplib] Conditional blocks"
- Reply: Zakaria: "Re: [phplib] Conditional blocks"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

