Php Smarty变量值如果否则

时间:2014-12-15 18:08:01

标签: php if-statement smarty whmcs

对不起,我不知道如何提问,因为我的知识很少。 我将举例说明我正在尝试做的事情:

消息:no records found如果您在部门“7”中没有票证

{if $ticket.did["7"] == ''} 
   No records found!
{/if}

我的Whmcs tpl代码:

{foreach from=$tickets item=ticket}
    {if $ticket.did == '7'}
    <tr>
        <td>#{$ticket.tid}</td> 
        <td>{$ticket.title}</td> 
        <td>{$ticket.status}</td>
        <td><a href="viewticket.php?tid={$ticket.tid}&c={$ticket.c}">View</a></td>
    </tr>
    {/if}
{/foreach}
    {if $ticket.did["7"] == ''} 
    <tr>
        <td colspan="6" class="textcenter">{$LANG.norecordsfound}</td>
    </tr>
    {/if}

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以初始化新变量,并在满足循环条件时将其设置为true。

    {foreach from=$tickets item=ticket}
    {if $ticket.did == '7'}
    {assign var="ticketFound" value="true"}
    <tr>
        <td>#{$ticket.tid}</td> 
        <td>{$ticket.title}</td> 
        <td>{$ticket.status}</td>
        <td><a href="viewticket.php?tid={$ticket.tid}&c={$ticket.c}">View</a></td>
    </tr>
    {/if}
{/foreach}
    {if !$ticketFound} 
    <tr>
        <td colspan="6" class="textcenter">{$LANG.norecordsfound}</td>
    </tr>
    {/if}