【问题标题】:How to filter if with 2 variables如果有 2 个变量,如何过滤
【发布时间】:2012-12-12 21:32:45
【问题描述】:

如果attribute_set 为1 且attributeText 为零,我想显示一些数据

AttributeSetId = 10 属性 = myattribute,包含:零、一、力

<?php if ($_product->getAttributeSetId() == "10"): && ($_product->getAttributeText('myattribute') == "Zero"):?> 

My data

<?php endif; ?>

怎么了?

感谢任何帮助。

自己解决:

<?php if ($_product->getAttributeSetId() == "10" && $_product->getAttributeText('myattribute') == "Zero"):?>

【问题讨论】:

    标签: magento filter attributes


    【解决方案1】:

    只是一些放错位置的括号。

    <?php 
    if ($_product->getAttributeSetId() == "10" && 
        $_product->getAttributeText('myattribute') == "Zero")  {
    ?>
    My data
    <?php } ?>
    

    我更喜欢使用大括号,但如果你愿意,可以使用 if/endif。

    【讨论】:

    • 性能方面没有区别。我更喜欢它,因为它是我习惯的样式,而且(重要的是)您可以在文本编辑器中使用“大括号匹配”在左大括号和右大括号之间切换(例如 Sublime Text 中的 Ctrl+M)。见here
    猜你喜欢
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多