【问题标题】:Smarty issue with nested conditional statements嵌套条件语句的 Smarty 问题
【发布时间】: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-&gt;oxcategories__oxsort 的值。但是,我建议您遵循 skrilled 的提示,仅将您需要的数据发送到表单。

标签: php smarty oxid


【解决方案1】:

因为我发现您忘记在排序顺序调用中写入值。 你只需要像我添加的那样在下面的行中赋值,它应该可以工作。

[{if ((int)$ocat->oxcategories__oxsort->value <100) }]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 2012-02-17
    • 2013-07-03
    相关资源
    最近更新 更多