Re: [PHP] pulling in template file in var and populating vars?

2006-03-23 Thread Kevin Waterson
This one time, at band camp, clive [EMAIL PROTECTED] wrote:

 You could also look at using a templating engine like Smarty for instance.

BHAHAHAHAHAHAHAAA
1000 lines of code for hello world



-- 
Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pulling in template file in var and populating vars?

2006-03-23 Thread Richard Lynch
On Wed, March 22, 2006 3:02 pm, blackwater dev wrote:
 I have a chunk of html data that I want to output for each iteration
 through
 a db result

 while($result){

$list.=file_get_contents(my_template_file.php);

 }
 return $list;

 The template file looks like this:

 table
 tr
  td?php echo $result[name];?/td
 /tr
 /table

 I basically want a good way to keep the template file out of the class
 so I
 don't have to code:
  $list.=tabletr...etc

 The problem is with the method I have, it doesn't translate the
 vars...what's the best way to do this?

You have a home-brew templating engine, and you've run into the EXACT
SAME problem every other templating engine has ever had...

So you REALLY ought to look at how Smarty solved it, how PEAR solved
it, how all the other templating engines solved it.

Be Warned:
You're going to go for awhile, and then run into ANOTHER problem which
is the EXACT SAME problem every other PHP Template author has hit.

And you're going to REPEAT this process indefinitely...

Maybe this is a case where re-inventing the wheel is a Bad Idea.

At a minimum, you ought to understand very well how all the other
wheels work, and don't work -- which it is clear from the question
that you don't.

Keep on rollin' :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pulling in template file in var and populating vars?

2006-03-22 Thread John Nichel

blackwater dev wrote:

I have a chunk of html data that I want to output for each iteration through
a db result

while($result){

   $list.=file_get_contents(my_template_file.php);

}
return $list;

The template file looks like this:

table
tr
 td?php echo $result[name];?/td
/tr
/table

I basically want a good way to keep the template file out of the class so I
don't have to code:
 $list.=tabletr...etc

The problem is with the method I have, it doesn't translate the
vars...what's the best way to do this?

Thanks!



I wouldn't use a class/function to output anything.  Why not just return 
the data, and loop thru that?


function myFunction() {
/* - Code - */
while ( $data = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
$return_data[] = $data;
}
}
return $return_data;



$myData = myFunction();
foreach ( $myData as $data ) {
echo END
table
tr
td$data[name]/td
/tr
/table
END;
}

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pulling in template file in var and populating vars?

2006-03-22 Thread Jim Lucas

blackwater dev wrote:

I have a chunk of html data that I want to output for each iteration through
a db result

while($result){

   $list.=file_get_contents(my_template_file.php);

}
return $list;

The template file looks like this:

table
tr
 td?php echo $result[name];?/td
/tr
/table

I basically want a good way to keep the template file out of the class so I
don't have to code:
 $list.=tabletr...etc

The problem is with the method I have, it doesn't translate the
vars...what's the best way to do this?

Thanks!

  

check into the eval() function

I see reading in the user notes that you will want to do something like
$filedata = file_get_contents($file);
while ($result) {
 $list .= eval('?'.$filedata);s
}

Looks like someone has figured this out.

You might also look into using str_replace and use markers in your 
template file


{SOME_VAR}

and then set in your while loop

$some_var = $result['something'];
$list .= str_replace('{SOME_VAR}', $some_var, $filedata);

This might work for you also

Jim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] pulling in template file in var and populating vars?

2006-03-22 Thread clive

You could also look at using a templating engine like Smarty for instance.

clive

blackwater dev wrote:

I have a chunk of html data that I want to output for each iteration through
a db result

while($result){

   $list.=file_get_contents(my_template_file.php);

}
return $list;

The template file looks like this:

table
tr
 td?php echo $result[name];?/td
/tr
/table

I basically want a good way to keep the template file out of the class so I
don't have to code:
 $list.=tabletr...etc

The problem is with the method I have, it doesn't translate the
vars...what's the best way to do this?

Thanks!



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php