为什么 smarty greater than function 不起作用?

Why smarty greater than function doesn't work?

我尝试插入以下代码以从我的在线商店的“添加到购物车”按钮中替换 CSS 样式,因此当产品为 0 时需要显示 "Order" 而不是产品大于 1 需要显示 "Add to Cart",但是 class .hideen(大于 >= )不起作用,而另一个是..

{if $product->quantity <= 0}
<style type="text/css">
{literal}
.hideeen {display:none;}
{/literal}
</style>
{/if}
{if $product->quantity >= 1}
<style type="text/css">
{literal}
.hideen {display:none;}
{/literal}
</style>
{/if}

你能看到 HTML where 将应用到哪里:

<button type="submit" name="Submit" class="exclusive">
<span class="btn">
{if $content_only && (isset($product->customization_required) && $product->customization_required)}<em>{l s='Customize'}</em>{else}<em class="hideeen">{l s='Add to cart'}</em>{/if}<em class"hideen">{l s='order'}</em>
</span>
</button>

上HTML错过了=那里<em class"hideen">{l s='order'}</em>

Smarty 使用某种 xml 解析器,因此代码应该有效 xml.
大于号制动 xml 结构。

最佳解决方案是使用 lt/gt 函数:

{if $product->quantity gt 1}  

其他选项可以是:

  • <![CDATA[]]> 标记将此部分包裹起来。
  • 使用反转条件:1 <= $q