Re[2]: [SMARTY] switch statement ?
| From: | Peter Bowyer | Date: | Wed, 01 May 2002 12:30:49 +0000 |
| Subject: | Re[2]: [SMARTY] switch statement ? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3945@lists.php.net to get a copy of this message | ||
At 11:20 AM 4/29/02 +0200, Bertrand DUNOGIER wrote:
and a switch / case is not harder to understand than a if / elseif / else is it ? :)But for your kind of example a switch may still be overkill. What we want is the good old PHPLib (or is it IT[X]?) kind of section/block: <!-- Template --> {block name="LoggedIn"} You are logged into our site. Fancy that! {/block} {block name="LoggedOut"} Can you find the link to login. I think not... {/block} /* PHP Code */ $smarty->default_block_status = 'visible'; if (isset($_SESSION['AUTH'])) {
$smarty->hide_block('LoggedOut');
} else {
$smarty->hide_block('LoggedIn');
}
Or of course you could have all blocks hidden by default, and then use $smarty->show_block() to make the right ones visible.
The advantage with this construct is that it puts the logic firmly where it should be: back in your PHP code. I'm not suggesting that blocks should be repeatable like in PHPLib as {section} does that, but I do think that simple blocks like this would be a very good idea.
Peter.
--
Maple Design - quality web design and programming
http://www.mapledesign.co.uk