Re: [SMARTY] switch instruction in smarty?

From: Date: Fri, 21 Oct 2005 16:03:05 +0000
Subject: Re: [SMARTY] switch instruction in smarty?
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13111@lists.php.net to get a copy of this message
this doesn't answer your question, but it might help debug... don't use the assign() fn. just use the $smarty.get.var in the if statement. eg. {if $smarty.get.cmd eq "main" || $smarty.get.cmd eq ""} should work, no? for your main question: just use the if elseif else construct suggested by Pete Morgan in the previous post. dan pbaker had written:
Hi, thank U but this not solve my problem, this is a sample of my code (tab menu on top of my page): [code] {assign var="tab" value=$smarty.get.cmd} <table border="0" cellpadding="0" cellspacing="0" height="20" class="tabmain"> <tr> {if $tab eq "main" || $tab eq ""}
        <td align="center" nowrap bgcolor="#FFDF54"><span
        class="mm">Main</span></td>
{else}
        <td align="center" nowrap bgcolor="#F4F5F6"><a
        href="{$SCRIPT_NAME}?cmd=main" class="mm">Main</a></td>
{/if} {if $tab eq "last"}
        <td align="center" nowrap bgcolor="#FFDF54"><span
        class="mm">Last</span></td>
{else}
        <td align="center" nowrap bgcolor="#F4F5F6"><a
        href="{$SCRIPT_NAME}?cmd=last" class="mm">Last</a></td>
{/if} [/code] if user type '?cmd=qwerty' i want to display the default value (first if) ________________________________________________________________________
Hi,
I think you have to take a look at the {else} and {elseif} functions:
http://smarty.php.net/manual/en/language.function.if.php
{if $foo eq "something"} <tr><td>show a</td></tr> {elseif $foo eq "blablabla"} <tr><td>shob b</td><tr> {else} <tr><td>default value</td></tr> {/if}
Does this solve your problem?
pbaker wrote:
Hi, i have a problem with my templates. this is some template... [code] {assign var="foo" value=$smarty.get.bar} {if $foo eq "something"} <tr><td>show my webpage</td></tr> {/if} {if $foo eq "somethingelse"} <tr><td>show another page</td></tr> {/if} ..... ..... [/code] everything is ok when the foo variable eq the $smarty.get.bar but i want to display the default value... ! i want to do in smarty something like switch instruction in php... any suggestion? ps.: sorry 4 my english :P


« previous php.smarty.general (#13111) next »