Smarty 数组显示匹配字符串

Smarty array show matching string

我不确定我问的对不对,但问题很简单:

我得到了一个带代码的 Smarty 数组

<td>
    {foreach from=$referrals item=referral}
        {$referral.service} - {$referral.service|@count}</br>
    {/foreach}
</td>

结果是这样的:Screenshot of array result

我的数组是这样的:

 Smarty_Variable Object (3)
->value = Array (29)
  0 => Array (11)
    id => "1433"
    date => "25/12/2015"
    service => "Деловен именик"
    package => "Деловен именик"
    userid => "469"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  1 => Array (11)
    id => "1434"
    date => "25/12/2015"
    service => "Лого со податоци"
    package => "Лого со податоци"
    userid => "469"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  2 => Array (11)
    id => "1435"
    date => "25/12/2015"
    service => "Реклама во црно-бела техника на 1/6 -..."
    package => "Реклама во црно-бела техника на 1/6 -..."
    userid => "469"
    amount => "6160.00"
    billingcycle => "One Time"
    amountdesc => "6.160,00 ден. One Time"
    commission => "1.232,00 ден."
    lastpaid => "Never"
    status => "Active"
  3 => Array (11)
    id => "1436"
    date => "25/12/2015"
    service => "Лого со податоци"
    package => "Лого со податоци"
    userid => "470"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "1.848,00 ден. One Time"
    commission => "369,60 ден."
    lastpaid => "Never"
    status => "Active"
  4 => Array (11)
    id => "1437"
    date => "25/12/2015"
    service => "Деловен именик"
    package => "Деловен именик"
    userid => "471"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"

我只想显示名称为“Деловен именик”的数组字符串或值,其余的则隐藏。 所以最后会有这样的结果:Screenshot final result -wanted

您是否尝试过将 {if} 添加到您的 {foreach} 循环中?

它可能就像这里展示的一样简单:

<td>
    {foreach from=$referrals item=referral}
        {if $referral.service eq "Деловен именик"}
            {$referral.service} - {$referral.service|@count}</br>
        {/if}
    {/foreach}
</td>

但是,这是一种相当专业的方法,如果要过滤不同的内容,则必须编辑模板。如果这是更通用解决方案的基础,您最好在 php 中编写一些代码,可能是数组中要过滤的另一个项目。