Re: Please: XTemplate help?

From: Date: Sat, 20 Jan 2001 19:03:03 +0000
Subject: Re: Please: XTemplate help?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35826@lists.php.net to get a copy of this message
Kristi, That makes more sense, thanks, but one problem - I don't want to have to do: $template->assign("FIELD2", $row[fieldname2]); If I've already called mysql_fetch_array, then I have an array like this: field1:field1_data field2:field2_data field3:field3 data Is there any way to use the array itself as the assignment, or tell XTemplate to do so? That way I can use one file to generate pages from different templates. Regards, Jaxon On 1/20/01 12:26 PM, "Kristi Russell" <darkfires@darkfires.com> wrote: > require "xtpl.p"; //include XTemplate engine > > //don't need this - wrong. >> require "html.xtpl"; //html layout file with field names e.g. {firstfield} > > You need to create a new instance of the Xtemplate class so: > //assign the new instance to a variable name you'll use - I called it > $template > //and I specified which "html layout file" to use. > > $template = new Xtemplate("html.tpl"); // I name them tpl not xtpl *shrug* > > while($row = mysql_fetch_array($result)) > { > $template->assign("FIELD1", $row[fieldname]); > //FIELD1 being the name you're going to use in the layout file by > {FIELD1} > //$row being the name of the array you fetched, field name being the > fieldname in the database > > $template->assign("FIELD2", $row[fieldname2]); > > $template->parse("main");//replace {field} with matching result row > element > $template->out("main");` //send final html page to browser > } > > > > Kristi > >

« previous php.general (#35826) next »