Re: Easy Template class?
| From: | Joe Stump | Date: | Mon, 13 Nov 2000 04:20:56 +0000 |
| Subject: | Re: Easy Template class? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24910@lists.php.net to get a copy of this message | ||
Can I ask why you guys add another layer of fat to your programming? Stuff
like this has never made much sense to me...
--Joe
On Sun, Nov 12, 2000 at 10:21:46PM -0500, Lawrence.Sheed@dfait-maeci.gc.ca wrote:
> I generally build a string in row/table stuff, and blat that out into my
> placeholder.
>
> So instead of
>
> <!-- BEGIN myrows -->
> <b>{rowelement}</b><br>
> <b>{rowelement1}</b><br>
> <b>{rowelement2}</b><br>
> <!-- END myrows -->
>
> I do:
>
> <!-- BEGIN myrows -->
> <b>{rowelement}</b><br>
> <!-- END myrows -->
>
> $sqlstring = "SELECT * FROM users";
> $result=@mysql_query($sqlstring,$db);
> if ($row = mysql_fetch_array($result)) {
> do {
> $string = $string . "<td>".$row ["username"] .
> "</td></tr>";
> } while($row = mysql_fetch_array($result));
> }
>
> ParseFile ($content, "{rowelement}", $string);
>
> -----Original Message-----
> From: Roy Nasser [mailto:roy@vem.ca]
> Sent: November 13, 2000 12:17 PM
> To: 'Lawrence.Sheed@dfait-maeci.gc.ca'; php-general@lists.php.net
> Subject: RE: [PHP] Easy Template class?
>
>
> But this wont be able to get me "row" support, would it?
>
> Like:
>
> <!-- BEGIN myrows -->
> <b>{rowelement}</b><br>
> <!-- END myrows -->
>
> and then when called something like:
>
> $t->SetVarRow("MyTemplateA","myrows","rowelement",$RowElem);
>
> in a for, or somethng,...
>
> > -----Original Message-----
> > From: Lawrence.Sheed@dfait-maeci.gc.ca
> > [mailto:Lawrence.Sheed@dfait-maeci.gc.ca]
> > Sent: Monday, November 13, 2000 1:06 AM
> > To: roy@vem.ca; php-general@lists.php.net
> > Subject: RE: [PHP] Easy Template class?
> >
> >
> > I do something along the lines of the code below.
> >
> > template_class.php
> > <?php
> >
> > function LoadFile ($filename){
> > if (file_exists($filename)) {
> > $fd = fopen( $filename, "r" );
> > $contents = fread( $fd, filesize( $filename ) );
> > //fclose( $fd );
> > }
> > else {
> > $contents = "<br><font color=red>Unable to
> > open:$filename</font></br>";
> > }
> > return ($contents);
> > }
> >
> > function ParseFile (&$contents,$item,$newvalue) {
> > $contents = ereg_replace ($item,$newvalue,$contents);
> > }
> > ?>
> >
> > Example parser
> >
> > <?php
> > include "template_class.php";
> > $contents = LoadFile ("example.html");
> >
> > ParseFile ($contents, "{TITLE}", "my brand new title here");
> >
> > print ($contents);
> >
> > ?>
> >
> >
> > example.html
> > <html>
> > <title>
> > {TITLE}
> > </title>
> > stuff here...
> > {MENU}
> > </html>
> >
> >
> > To embed one file within another, you can do:
> >
> >
> > example2.html
> > <menu stuff here>
> > ...
> > </menu stuff>
> >
> >
> > 2nd_example.php
> > <?php
> > include "template_class.php";
> > $contents = LoadFile ("example.html");
> > $menu = LoadFile ("example2.html");
> >
> > ParseFile ($contents, "{TITLE}", "my brand new title here");
> > ParseFile ($contents, "{MENU}",$menu);
> >
> > print ($contents);
> >
> > ?>
> >
> > Simple hey!
> >
> > Cheers,
> >
> > Lawrence.
> > -----Original Message-----
> > From: Roy Nasser [mailto:roy@vem.ca]
> > Sent: November 13, 2000 11:12 AM
> > To: Php (E-mail)
> > Subject: RE: [PHP] Easy Template class?
> >
> >
> > I think i moaned a little bit too much in my last e-mail but
> > didnt provide
> > any suggestions for what i wanted... Here goes:
> >
> > I think that Instead of having a set_var with jsut the name
> > of the template
> > variable and the value, it should be something like:
> >
> > Set_Var("SomeVariable",$SomeValue,"MyTemplateA");
> > Set_Var("SomeDifferentVariable",$SomeOtherValue,"MyTemplateB");
> >
> > And then something like:
> >
> > Embed_Template("Menu","MyTemplateA","MyTemplateB");
> >
> > What this would do is:
> >
> > #1: {SomeVariable} in MyTemplateA would become $SomeValue
> > #2: {SomeDifferentVariable} in MyTemplateB would become
> > $SomeOtherValue
> > #3: {Menu} in MyTemplateA would become MyTemplateB with
> > everything that has
> > been done to it (Such as the {SomeVariable})
> >
> > Thanks again....
> >
> >
> >
> > Roy Nasser
> > CTO
> > Vem Cá Servicos de Internet S/C Ltda.
> > Av. Paulista 2421 14* Andar
> > São Paulo SP Brasil
> > 55 11 3347 3456 / 9953 8853 - cel
> > www.jarbas.com.br
> > roy@vem.ca
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail:
> > php-list-admin@lists.php.net
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
================================================================================
= Joe Stump joestump98@yahoo.com http://www.miester.org =
================================================================================
"Real programmers don't comment their code.
It was hard to write, it should be hard to understand."