如何检查一个值是否以'A2'自作聪明的家伙

How can I check if a value starts with 'A2' in smarty?

本文关键字:A2 自作聪明 检查 何检查 一个 是否      更新时间:2023-09-26

问题:
如何检查一个值是否以'A2''A7'等开头?如果值为'A2'只显示'$aWoning.Woning_Bouwnr''A2'开头的所有行?因为我是Smarty的新手,我真的不知道现在该做什么。

Code/Html:

<table id="bouwnummers-table" class="table table-hover table-striped">
                            <thead>
                            <tr>
                                <th>Bouwnummer</th>
                                <th>Woningtype</th>
                                <th>Woonopp.</th>
                                <th>Prijs vanaf</th>
                                <th>Status</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach $aWoningen as $aWoning}
                                <tr>
                                    <td>{$aWoning.Woning_Bouwnr}</td>
                                    <td>{$aWoning.Projectwoning_Titel}</td>
                                    <td>{$aWoning.Woning_WoonOpp} m&sup2;</td>
                                    {*<td>{$aWoning.Woning_Adres|escape}</td>*}
                                    <td>
                                        {if $aWoning.Woning_Prijs!=0}
                                            {if $aWoning.Verkocht!=1}
                                                {$aWoning.Woning_Prijs|escape:"html"|lv_hele_euro}
                                            {else}
                                                Verkocht
                                            {/if}
                                        {else}
                                            n.n.b.
                                        {/if}
                                    </td>
                                    <td class="{if $aWoning.Verkocht==1}status-verkocht{elseif $aWoning.Optie==1}status-optie{else}status-beschikbaar{/if}">
                                        <i class="fa fa-square"></i>
                                        {if $aWoning.Verkocht==1}
                                            Verkocht
                                        {elseif $aWoning.Optie==1}
                                            In Optie
                                        {else}
                                            Beschikbaar
                                        {/if}
                                    </td>
                                </tr>
                            {/foreach}
                            </tbody>
                        </table>

和php一样,使用strpos

{if $yourVarToCheck|strpos:"A2"!== false}

也许你可以

{if $value|strpos:'A2' !== false && $value|strpos:'A2' === '0'}

if return '0' position表示它在字符串

中从A2开始

或更好的方法

{if $value|strstr:'A2' && $value|strpos:'A2' === '0'}

使用strstr代替strpos检查真或假

Smarty可以使用"normal" php函数

:

{if $yourVarToCheck|strstr:"A2"}
    //your code here
{/if}