Page 1 of 1

how whould you do it?

Posted: Thu May 08, 2003 3:45 pm
by CONFIQ
let's say...
you have file> html.tpl and in it

Code: Select all

<table $var $var2></table>
how whould you echo this HTML part if it is in while and that all variables whould be loaded.
'Till now i've figure something like this
index.php:

Code: Select all

<?php
for($i=1,$i>10,$i++){
$var=$i+1;
$var2=$i-1;
include("html.tpl");
}
?>
but it dosen't seems "handsome" to me... and i don't like include in this case...
is there a better way to do it?

Posted: Thu May 08, 2003 4:09 pm
by Heavy
The PHP function eval() parses a string as PHP code.
see:
http://www.php.net/manual/en/function.eval.php

Posted: Thu May 08, 2003 5:52 pm
by CONFIQ
Hmmm, something like

Code: Select all

<?php
$string = implode('', @file('html.tpl'));
for($i=1,$i>10,$i++){ 
$var=$i+1; 
$var2=$i-1; 
eval ('?>' . $string);
} 
?>
   
good idea,thank you :)

Posted: Fri May 09, 2003 4:28 am
by []InTeR[]
Easy'st:

Code: Select all

<table <? echo $var.$var2 ?>></table>
In your tempate.

The best is to use a existing template engine.
I use Yapter.

Posted: Fri May 09, 2003 4:43 am
by Heavy
Often, the purpose of using templates is to let design matters go into files where no PHP goes. None of the examples above provide this except for Yapter, which seems to be a nice template engine. I haven't tried it myself, but I read about it on http://www.yapter.com

Posted: Fri May 09, 2003 9:19 am
by CONFIQ
it remainds me on smarty.php.net ...
Anyway i can't use any template, i need something simple like this :)