RE: [PHP] Easy Template class?

From: Date: Mon, 13 Nov 2000 05:03:02 +0000
Subject: RE: [PHP] Easy Template class?
Groups: php.general 
Request: Send a blank email to php-general+get-24915@lists.php.net to get a copy of this message
Joe, I think you miss the point somewhat. For me, most of my work is for a number of languages. I typically have to do stuff in Simplified Chinese, Traditional Chinese, French, English and occasionally Dutch. Having code abstracted from html makes it easier for the web designer to work with what they're good at. I can also change the look of the sites I do by changing the templates easily. If you code stuff into certain places, you're kind of restricted to how you've coded it. I do a lot of consulting in Shanghai. Most of my work is outsourced from other web design companies, who to be honest haven't got a clue. When their client tells them, how about this in bold, and underline? then having a template for them to add bold, underline to rather than mess up code makes it infinitely easier. Templates are useful in their place, but if you're doing simple stuff, you don't neccesarily need them. I tend to do multi language stuff as I've said, and for me, the translators, and the companies I work with, templatization makes a big difference to *my* workload. Code once, let them futz with the look! cheers, Lawrence. -----Original Message----- From: Joe Stump [mailto:joe@earth.care2.com] Sent: November 13, 2000 12:46 PM To: Roy Nasser Cc: php-general@lists.php.net Subject: Re: [PHP] Easy Template class? <!-- DO NOT REMOVE THIS MORON!!!! --> <? $bla->bbb(); ?> <!-- DO NOT REMOVE THIS MORON!!!! --> :O) --Joe On Mon, Nov 13, 2000 at 02:44:33AM -0300, Roy Nasser wrote: > I understand your point of viw... > > but this being my 3rd project with a Design Company, i think i better try > these simple Templates... > > You'd be amazed at how inteligent designers are, to the lever of "Sir i > deleted those weird <?$bla->bbb();'?> because they were screwing up my > preview of the page".... > > We'll see... i'll tell you my findings in the end of the prject (Should be > done in about 8 - 9 days) > > > -----Original Message----- > > From: Joe Stump [mailto:joe@earth.care2.com] > > Sent: Monday, November 13, 2000 2:36 AM > > To: Roy Nasser > > Cc: php-general@lists.php.net > > Subject: Re: [PHP] Easy Template class? > > > > > > <!-- ever heard of comments --> ??? > > > > Or how about nice fast functions that display the content - > > so you have a cool > > function that returns the results of say "company news" like this: > > > > function get_results($sql){ > > if(strlen($sql)){ > > $r = mysql_query($sql); > > if(@mysql_num_rows($r)){ > > while($row = mysql_fetch_array($r)){ > > $ret[] = $row; > > } > > }else{ > > $ret = 0; > > } > > }else{ > > $ret = 0; > > } > > > > return $ret; > > } > > > > Then have a function that formats all of your content: > > > > function show_news(){ > > $results = get_results('SELECT * FROM news'); > > while(list($key,$val) = each($results)){ > > echo '<LI>'.$val['title']; > > } > > } > > > > That way you have a nice fast function that only consists of > > on line of code - if your designers can understand {news} then they > > sure as heck should be able to grasp <? show_news(); ?> > > > > > > Just my $0.02 > > > > --Joe > > > > > > On Mon, Nov 13, 2000 at 02:28:36AM -0300, Roy Nasser wrote: > > > Joe, > > > > > > This is the first time i program with Templates (as you might have > > > noticed)... And i have decided to do this because we are > > now working with a > > > company that is desigining our site... The designers do not > > work directly > > > with us programmers, so it is best to just have the design > > come in in > > > "Templates" than just cutting and pasting thousands of > > lines of HTML, into > > > thousands of lines of PHP... > > > > > > It does start to make sense.... > > > > > > I am also using a class called GENERALIZED_CACHED_TEMPLATE, > > and this allows > > > me to interface with many templkate styles, and also allows > > me to Cache ANY > > > output... > > > > > > Basically, i create ONE copy of a page (That can take upto > > 2 - 5secs - > > > depending on MySQL queries, for example), and then server subsequent > > > requests to that page from a disk copy, and the 2 - 5 secs, > > takes about > > > 0.05secs on a RAID5 SCSI! or about 0.09 on my home ATA IDE...! > > > > > > This, combined with the ease of talking to "dumb*" > > designers is reason > > > enough to convince me! > > > > > > > > > > > > ------------------------ > > > dumb: refers to people who are not "PHP Compliant" :) > > > > > > > > > > -----Original Message----- > > > > From: Joe Stump [mailto:joe@earth.care2.com] > > > > Sent: Monday, November 13, 2000 2:21 AM > > > > To: Lawrence.Sheed@dfait-maeci.gc.ca > > > > Cc: roy@vem.ca; php-general@lists.php.net > > > > Subject: Re: [PHP] Easy Template class? > > > > > > > > > > > > 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." > > > > > > ============================================================== > > ================== > > = 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." > > ============================================================================ ==== = 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." -- 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

« previous php.general (#24915) next »