2014-09-26 56 views
0

我有一個關於smarty和OXID eShop的小問題。在檢索一組類別之後,我嘗試僅顯示「排序號碼」特殊範圍內的類別。應顯示低於100的所有值。但是,這也顯示了項目> 100Smarty問題嵌套條件語句

這裏是我的代碼片段:

[{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}] 

任何想法,問題出在哪裏可以?

+2

爲什麼使用模板引擎來執行邏輯操作?如果您只想顯示100個類別,則只應從控制器/模型向視圖發送100個類別。 – skrilled 2014-09-26 19:45:45

+0

它可能與你在第二個if語句中對'int'的轉換有關。也許這個演員陣容正在做你不想做的事情,因爲如果你必須先演員,那麼顯然這是另一回事。當你將它轉換爲int類型時,你可以試着查看'$ ocat-> oxcategories__oxsort'的值。但是,我會建議您遵循skrilled的提示,並且只將您需要的數據發送到表單。 – Bono 2014-09-26 21:33:53

回答

2

因爲我發現你忘記了在你的sortorder調用中寫入值。 你只需要在下面的行值,因爲我補充說,它應該工作。

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

這應該被標記爲正確的答案。 – Roman 2015-11-11 22:50:44