HTML/Template_ITX : blocks shown even if not declared.
| From: | Nicola Delbono | Date: | Sun, 11 Jan 2004 10:25:21 +0000 |
| Subject: | HTML/Template_ITX : blocks shown even if not declared. | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-10100@lists.php.net to get a copy of this message | ||
Hello,
I have a template file with normal html, {variables} and <!-- blocks -->
If in html I have, let's say, a variable called {mailfrom}
and in the same template file I have a block (<!-- BEGIN mail_detail -->)
which contains also the variable called {mailfrom} , this block
will be displayed anyway, even If I so not "use it" in the PHP file.
Typical situation: A Webmail Manager.
Short example:
This is the template: maildetail.html
<html>
Hello <b>{username}</b>, this is your INBOX, click a mail message to have it displayed
below.
<!-- BEGIN mail_detail -->
Mail display for {username}. Here is the mail you wanted.
From: {mailfrom} To {mailto} Subj: {subject}
Body: {body}
<!-- END mail_detail -->
<!-- BEGIN no_detail -->
No email selected
<!-- BEGIN no_detail -->
<html>
<?php
/* this is the php file */
include_once 'HTML/Template/ITX.php';
$tpl =& new HTML_Template_ITX('./tpl');
$tpl->loadTemplateFile('maildetail.html', TRUE, TRUE);
if(isset($_GET['display']) && $_GET['display'] == 1) {
$tpl->setCurrentBlock('maidisp');
$tpl->setVariable(array(
'mailfrom'=>$mdata['mailfrom'],
'subject'=> $mdata['mailsubj'],
'body'=> $mdata['mailbody'],
));
$tpl->parseCurrentBlock();
} else {
$tpl->setCurrentBlock('no_detail');
$tpl->parseCurrentBlock();
}
$tpl->setVariable('username', $username);
$tpl->show();
?>
The directive
$tpl->setVariable('username', $username);
will cause mail_detail to be displayed even if not set.
Is there a way to avoid this situation except by using different template
variable for the same php variable ($username)?
--
A: No.
Q: Should I include quotations after my reply?