Rodrigo Bogdanowicz
Rodrigo Bogdanowicz

Reputation: 71

Php Smarty Variable with value if else

I'm sorry, I do not know how to ask the question because my knowledge is small. I'll give an example of what I'm trying to do:

The message: no records found if you have no ticket in the department "7"

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

My Whmcs tpl code:

{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}

Thanks!

Upvotes: 0

Views: 927

Answers (1)

David Kuna
David Kuna

Reputation: 94

You can initialize new variable and set it true when the condition in loop will be satisfied.

    {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}

Upvotes: 2

Related Questions