【发布时间】:2014-09-26 19:01:07
【问题描述】:
我有一个关于 smarty 和 OXID eShop 的小问题。检索一堆类别后,我尝试仅显示“排序号”特殊范围内的类别。应该显示低于 100 的所有内容。但它也显示大于 100 的项目。
这是我的代码 sn-p:
[{foreach from=$oxcmp_categories item=ocat key=catkey name=root}]
[{if $ocat->getIsVisible() }]
[{if ((int)$ocat->oxcategories__oxsort <100) }]
[{if $smarty.foreach.root.index % 3 == 0}]
<div style="clear: left;"></div>
<div class="mainMenu sub_[{$smarty.foreach.root.index}]">
<div class="mm_header">
<p class="mm_headline">[{$ocat->oxcategories__oxtitle->value}]</p>
</div>
<div>
<img src="[{if $ocat->getThumbUrl() != ''}] [{$ocat->getThumbUrl()}] [{else}] [{'http://placehold.it/299x230'}] [{/if}]" alt="">
<p class="mm_desc">[{$ocat->oxcategories__oxdesc}]</p>
</div>
</div>
[{else}]
<div class="mainMenu sub_[{$smarty.foreach.root.index}]">
<div class="mm_header">
<p class="mm_headline">[{$ocat->oxcategories__oxtitle->value}]</p>
</div>
<div>
<img src="[{if $ocat->getThumbUrl() != ''}] [{$ocat->getThumbUrl()}] [{else}] [{'http://placehold.it/299x230'}] [{/if}]" alt="">
<p class="mm_desc">[{$ocat->oxcategories__oxdesc}]</p>
</div>
</div>
[{/if}]
[{/if}]
[{/if}]
[{/foreach}]
任何想法可能是问题所在?
【问题讨论】:
-
为什么要使用模板引擎来进行逻辑操作?如果您只想显示 100 个类别,您应该只将 100 个类别从控制器/模型发送到视图。
-
这可能与您在第二个
if-statement中对int的演员阵容有关。也许那个演员正在做一些你不希望做的事情,因为如果你必须先施放它显然是另一回事。当您将其转换为int时,您可以尝试查看$ocat->oxcategories__oxsort的值。但是,我建议您遵循 skrilled 的提示,仅将您需要的数据发送到表单。