RE: [PHP] FastTemplate Newbie

From: Date: Wed, 29 Nov 2000 18:23:21 +0000
Subject: RE: [PHP] FastTemplate Newbie
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27821@lists.php.net to get a copy of this message
Looks like you are already parsing MAIN. I don't think you can parse something twice. Move all of the parse lines to the end of the file, just above FastPrint Then change your function. You don't want it to echo anything in FastTemplate. Assign your output to a variable, then return the value at the functions end. Like this: Function array2links($arr) { while ( list( $key, $val ) = each($arr)) { $link = "<a href=\"view.php?Cat=$key\" title=\"$val\">$val</a><br>"; $buffer .= "$link"; } return $buffer } I hope this helps, if not don't hesitate to ask. I use FastTemplate all the time, and might be able to help. Robert Zwink <A HREF="http://zwink.levitate.org"> http://zwink.levitate.org </A> -----Original Message----- From: jblythe@bold.binarylogic.com.au [mailto:jblythe@bold.binarylogic.com.au]On Behalf Of Joseph H Blythe Sent: Tuesday, November 28, 2000 8:49 PM To: PHP-General Subject: [PHP] FastTemplate Newbie Hey all, I have converted a site I am working on from dreamweave templates (yucky) to FastTemplates, as you can imagine I am trying to seperate all php code away from html code so far so good. I have run into a problem though I can't seem to assign variables into the template (well I have sort of but with rather strange results) for example: I have a template variable named {COMPONENTS} in products.htm contents of index.php: <?php include($DOCUMENT_ROOT . "/include/class.FastTemplate.php3"); $tpl = new FastTemplate('.'); $tpl->define( array( 'main' => 'main.htm', 'products' => 'products.htm', 'header' => 'products_header.htm', 'navleft' => 'navleft.htm', 'products_index' => 'products_index.htm', 'login' => 'login.htm', 'footer' => 'footer.htm' ) ); $tpl->parse('PRODUCTS', 'products'); $tpl->parse('HEADER', 'header'); $tpl->parse('NAVLEFT', 'navleft'); $tpl->parse('PRODUCT_INDEX', 'products_index'); $tpl->parse('LOGIN', 'login'); $tpl->parse('FOOTER', 'footer'); $tpl->parse('MAIN', 'main'); // The array and following fuction would be included, I have stuck them here to make it more clear $Components = array( "ONE" => "Item One", "TWO" => "Item Two", "THREE" => "Item Three", "FOUR" => "Item Four", "FIVE" => "Item Five"); Function array2links($arr) { while ( list( $key, $val ) = each($arr)) { $link = "<a href=\"view.php?Cat=$key\" title=\"$val\">$val</a><br>"; echo "$link"; } } $tpl->assign(COMPONENTS, array2links($Components)); $tpl->FastPrint('MAIN'); ?> Now this seems to work but does not replace {COMPONENTS} in products.htm it just shoves all the output at the top of the file?? I have also tried: $tpl->assign(COMPONENTS, "Hello"); Which does nothing?? the {COMPONENTS} template variable remains in the final output. I have made sure that my spelling is correct on {COMPONENTS} so I don't really understand why I cant assign the variables as per the examples in the documentation. What am I missing?? Note: all the $tpl->parse(...); is working fine Any logic would be mutch appreciated Regards Joseph -- 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 (#27821) next »