Log in

View Full Version : Loop through text files.


Davey
05-18-2003, 10:55 AM
I want to make a "template" set (outside of vB), where the HTML is stored in text files and evaluated thereafter.
However, I have no idea how to go about looping through the text file.
Can anyone suggest any ideas?
Possibly Xenon since you're the only PHP expert online? :p

Dave.

Gary King
05-19-2003, 01:30 AM
Err no, xenon isn't the only PHP expert around here: just check out all the hack makers, and you'll get a rough idea of who the "PHP experts" really are ;)

Some quick instructions on how to go about doing this:

Place your text files in a database (you can use phpMyAdmin to insert the text files, just take a look at how vBulletin templates are).

Take a look at how the function gettemplate is. (/forum/admin/functions.php) That's what vB uses to get the templates from the database. You can copy and paste from // ###################### Start gettemplate #######################
until the next comment line (has several #s)
if you want, and see how that works out (be sure to change the table/column names to wherever your templates are stored.)

Then, find in functions.php // ###################### Start dooutput #######################
and copy and paste from there until the next comment line (it has several #s)

Then, in the actual PHP page where you want to echo the text files, type something like:

<?php

eval("dooutput(\"".gettemplate('templatename')."\");");

?>

That's all there is to it!

Davey
05-19-2003, 05:00 PM
I have only one word to say.
?

Dave.

Gary King
05-19-2003, 06:02 PM
If you don't understand it, then I suggest you start with something a little more simpler first ;)

Davey
05-19-2003, 08:15 PM
Dude in the dooutput function it seems to show another function called dovars, which completely looses me.
Besides.
At what part of dooutput does it loop through the text file to get the lines of HTML needed to insert into the DB, which as the function gettemplate shows, it selects the template from the DB.
Where's the "inserting it into the DB"?

Dave.

Gary King
05-19-2003, 08:21 PM
Place your text files in a database (you can use phpMyAdmin to insert the text files, just take a look at how vBulletin templates are).

Make a table named template, with at least these two columns:

title template

Insert template title name in title, and the actual template in template.