简体   繁体   中英

Why smarty greater than function doesn't work?

I have tried to insert the following code to alternate the CSS style from my Add to Cart button on my online store, so when the product are 0 that need to display "Order" instead product are greater than 1 that need to display "Add to Cart", but the class .hideen (with the greater than >= ) doesn't work instead the other one yes..

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

There can you see where the HTML where will be applied:

<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上,缺少= there <em class"hideen">{ls='order'}</em>

Smarty uses some kind of xml parser, so code should be valid xml.
GreaterThan sign brakes xml structure.

Best solution is to use lt / gt functions:

{if $product->quantity gt 1}  

Another options can be:

  • Wrap this section with <![CDATA[ , ]]> markers.
  • Use inverted conditions: 1 <= $q

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM