我认为我走在正确的轨道上,但没有像我希望的那样工作;我想用div包装器包装每两个项目,每两个项目将内容分解为新行,但不是我的工作方式。我对Smarty很新。
TPL
<div class="row-fluid">
<div class="span12">
{foreach from=$cart.products item="pp" key="pp_key" name="loop"}
{if $pp.extra.package_info.p_id == $key && !$pp.extra.package_info.hidden}
<div class="span6">
<p>{$pp.product_id|fn_specific_development_get_category}<br>
<a href="{"products.view&product_id=`$pp.product_id`"|fn_url}"> {$pp.product}</a>
</p>
{if $pp.product_options}
{include file="common/options_info.tpl" product_options=$cart_products.$pp_key.product_options}
{else}
-
{/if}
<p class="center">{$pp.amount / $product.amount}</p>
{if $product.price_rule == "S"}
<p>{include file="common/price.tpl" value=$pp.extra.package_info.f_price class="none"}</p>
<p>{include file="common/price.tpl" value=$pp.extra.package_info.f_price*$pp.amount class="none"}</p>
{/if}
</div>
{/if}
{if $pp.extra.package_info.p_id == $key}
<input type="hidden" name="cart_products[{$key}][package][{$pp.extra.package_info.table_key}][{$pp.extra.package_info.inc}][product_id]" value="{$pp.product_id}" />
<input type="hidden" name="cart_products[{$key}][package][{$pp.extra.package_info.table_key}][{$pp.extra.package_info.inc}][amount]" value="{$pp.amount / $product.amount}" />
{if $pp.product_options}
{foreach from=$pp.product_options key="opt_id" item="opt_value"}
<input type="hidden" name="cart_products[{$key}][package][{$pp.extra.package_info.table_key}][{$pp.extra.package_info.inc}][product_options][{$opt_id}]" value="{$opt_value}" />
{/foreach}
{/if}
{/if}
{if $smarty.foreach.loop.index is div by 2}
</div><div class="row-fluid">
{/if}
{/foreach}
</div>
</div>
它最终应该像....
<div class="row-fluid">
<div class="span6">....</div>
<div class="span6">....</div>
</div>
<div class="row-fluid">
<div class="span6">....</div>
<div class="span6">....</div>
</div>
<div class="row-fluid">
<div class="span6">....</div>
</div>
答案 0 :(得分:0)
对于其他想要知道的人,我的解决方案是:
使用迭代和strip来包装内容循环
{foreach from=$cart.products item="pp" key="pp_key" name="loop"}
{strip}
{if $pp.extra.package_info.p_id == $key && !$pp.extra.package_info.hidden}
<div class="span6">
<p>{$pp.product_id|fn_specific_development_get_category}<br>
<a href="{"products.view&product_id=`$pp.product_id`"|fn_url}"> {$pp.product}</a>
</p>
{if $pp.product_options}
{include file="common/options_info.tpl" product_options=$cart_products.$pp_key.product_options}
{else}
-
{/if}
<p class="center">{$pp.amount / $product.amount}</p>
{if $product.price_rule == "S"}
<p>{include file="common/price.tpl" value=$pp.extra.package_info.f_price class="none"}</p>
<p>{include file="common/price.tpl" value=$pp.extra.package_info.f_price*$pp.amount class="none"}</p>
{/if}
</div>
{/if}
{if $pp.extra.package_info.p_id == $key}
<input type="hidden" name="cart_products[{$key}][package][{$pp.extra.package_info.table_key}][{$pp.extra.package_info.inc}][product_id]" value="{$pp.product_id}" />
<input type="hidden" name="cart_products[{$key}][package][{$pp.extra.package_info.table_key}][{$pp.extra.package_info.inc}][amount]" value="{$pp.amount / $product.amount}" />
{if $pp.product_options}
{foreach from=$pp.product_options key="opt_id" item="opt_value"}
<input type="hidden" name="cart_products[{$key}][package][{$pp.extra.package_info.table_key}][{$pp.extra.package_info.inc}][product_options][{$opt_id}]" value="{$opt_value}" />
{/foreach}
{/if}
{/if}
{/strip}
{if $smarty.foreach.loop.last or $smarty.foreach.loop.iteration is div by 2}
</div><div class="row-fluid">
{/if}
{/foreach}