FastTemplate Newbie
| From: | Joseph H Blythe | Date: | Wed, 29 Nov 2000 04:48:47 +0000 |
| Subject: | FastTemplate Newbie | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-27777@lists.php.net to get a copy of this message | ||
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