Re: Re[2]: [SMARTY] switch instruction in smarty?

Daniel Hedrick <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
On Oct 21, 2005, at 3:35 PM, pbaker wrote:
> and if that user change by hand url like '?cmd=bug' (bug is not in my
> if rule!) i want to move him on default page ...

if you use assign:

{assign var="tab" value=$smarty.get.cmd}

and the querystring is ?cmd=bug or ?cmd=qwerty

then $tab will not be empty. it will be the value "bug" or "qwerty".  
That was why one of the suggestions was to use a "fall-through" for  
the main/default value. (of course, that's not as simple when the  
default should appear first in the template).

You could create a simple lookup table such that the keys and values  
are the same. If the key isn't found then null/emptystring will be  
returned:

<?php
//... myMap = { "a"=>"a","b"=>"b","c"=>"c" }...
$smarty->assign( "lookup", $myMap );
?>
...
{assign var="tab" value=$smarty.get.cmd}
{assign var="realTab" value=$lookup[$tab]}

-daniel
--
http://www.hedrick.org/daniel?sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.