如何在smarty中检查值是否以'A2'开头?
问题描述:
问题:
如何检查值是否以'A2'
,'A7'
等开头。如果值为'A2',则只显示'$aWoning.Woning_Bouwnr'
以'A2'
开头的所有行?由于我是Smarty的新手,我现在真的不知道该怎么做。如何在smarty中检查值是否以'A2'开头?
代码/ 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²</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>
答
Smarty的可以用 “正常” PHP-功能。
像这样:
{if $yourVarToCheck|strstr:"A2"}
//your code here
{/if}
答
在PHP中,使用strpos
{if $yourVarToCheck|strpos:"A2"!== false}
将返回误报,如果字符串是一样的东西 “B1主题A2” – Borgtex