我正在开发一个智能模板,我必须在一行中只显示2个公司名称我正在使用此代码
{foreach from=$found_users_sids item=user_sid name=users_block}
<div class="{cycle values = 'evenrow,oddrow' advance=true}">
{display property='username' object_sid=$user_sid assign='username'}
{display property='CompanyName' object_sid=$user_sid assign='companyNameAlias'}
{display property='State.Code' object_sid=$user_sid parent=Location assign='State'}
{display property='City' object_sid=$user_sid parent=Location assign='City'} <span>
<strong><a href="{$GLOBALS.site_url}/company/{$user_sid}/{$companyNameAlias|replace:" ":"-"|escape:"url"}/">{display property='CompanyName' object_sid=$user_sid}</a> </strong> {$City}{if $City && $State}, {/if}{$State}
</span>
</div>
{/foreach}
但它显示了这样的答案
immersive reasearch Centerville, MA
Integrated Resource Group Hartford, CT
Inventa Group Atlanta, GA
我希望像这样显示它
immersive reasearch Centerville, MA, Integrated Resource Group Hartford, CT
Inventa Group Atlanta, GA
我想提前感谢大家帮助我
答案 0 :(得分:0)
您应该添加条件显示yor div的开头和结尾,如下所示:
{foreach from=$found_users_sids item=user_sid name=users_block}
{if $smarty.foreach.users_block.iteration mod 2 eq 1}
<div class="{cycle values = 'evenrow,oddrow' advance=true}">
{/if}
{display property='username' object_sid=$user_sid assign='username'}
{display property='CompanyName' object_sid=$user_sid assign='companyNameAlias'}
{display property='State.Code' object_sid=$user_sid parent=Location assign='State'}
{display property='City' object_sid=$user_sid parent=Location assign='City'} <span>
<strong><a href="{$GLOBALS.site_url}/company/{$user_sid}/{$companyNameAlias|replace:" ":"-"|escape:"url"}/">{display property='CompanyName' object_sid=$user_sid}</a> </strong> {$City}{if $City && $State}, {/if}{$State}
</span>
{if $smarty.foreach.users_block.iteration mod 2 eq 0 or $smarty.foreach.users_block.last}
</div>
{/if}
{/foreach}