仅显示产品属性值(如果存在)
令人惊讶的是找不到任何关于此的内容...基本上我在产品视图页面上调用我的自定义产品属性,如下所示:
Men / Women: <?php echo $this->htmlEscape($_product->getmenwomen()) ?>
这可以很好地显示男士/女士属性,但这些是可选值,因此如果产品没有对于此特定属性的值,该行仍然显示,只是没有值:
Men / Women:
如果产品确实没有价值,我希望该行根本不显示。有什么想法吗?
Surprisingly can't find anything on this... basically I call my custom product attributes on the product view page like this:
Men / Women: <?php echo $this->htmlEscape($_product->getmenwomen()) ?>
This displays the men/women attribute fine, but these are optional values, so if a product doesn't have a value for this particular attribute, the line is still displayed, just with no value:
Men / Women:
I'd like that line to not show at all if there is indeed, no value for a product. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在打印之前,您必须检查 getmenwomen() 的值是否确实包含您期望它包含的内容(例如 men/women)。在此示例中,我假设除空格之外的任何内容都是有效值。
You have to check if the value of getmenwomen() really contains something you expect it to contain (eg men/women) before printing it. In this example i presume that anything but whitespace is a valid value.
对此不是 100%,因为我不确定 getmenwomen() 如果为空是否会返回 false
如果不返回任何内容,默认情况下应返回 false。
Not 100% on this because I am not sure if getmenwomen() will return false if its empty
If nothing is to be returned, by default it should return false.
您的意思是如果有值则希望显示所有内容,如果没有值则不显示任何内容?只需添加一个简单的条件:
就这样,您甚至不需要其中的 else 。
You mean you want to display everything if there is a value and nothing if there isn't? Just add a simple conditional:
and that's it, you don't even need an else in there.