【问题标题】:Why smarty greater than function doesn't work?为什么 smarty 大于函数不起作用?
【发布时间】:2017-01-05 16:40:49
【问题描述】:

我尝试插入以下代码来替换我在线商店上添加到购物车按钮的 CSS 样式,因此当产品为 0 时需要显示“订单”而不是产品大于 1 需要显示“添加到购物车”,但是 .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 的位置:

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

【问题讨论】:

  • 你真的用一个字符来区分这两个类吗(hideen vs hideeen)?这非常很容易被误读,而且我花费的时间比理解你的问题所花费的时间要长得多。考虑使用更易读的东西。
  • 为什么首先要为此设置两个不同的样式类?为什么不是 SINGLE 样式,而是使用类似 &lt;style&gt;.hide { display: {smartycodehere} }&lt;/style&gt; 的东西来生成只是一个无/块类型的东西?
  • 你在两个 if 条件下都使用相同的 css..那么为什么不只使用一个类??
  • 可读性是相对的,对 Sasha 可读的内容对你可能不可读;不会出错。
  • @MarcB 你是什么意思?我不明白你应该在 {smartycodehere} 上插入什么代码,你能更清楚地发布吗?我想显示一个并隐藏另一个(例如 CSS 上带有 @ 媒体的断点)。但我的第一个问题是,为什么“大于 >=”代码不起作用?当我尝试插入它时页面崩溃..

标签: php css smarty prestashop prestashop-1.6


【解决方案1】:

在 HTML 上错过= 那里有&lt;em class"hideen"&gt;{l s='order'}&lt;/em&gt;

【讨论】:

    【解决方案2】:

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

    最好的解决办法是使用lt/gt函数:

    {if $product->quantity gt 1}  
    

    其他选项可以是:

    • &lt;![CDATA[]]&gt; 标记将此部分包装起来。
    • 使用反转条件:1 &lt;= $q

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 2014-08-06
      • 2015-02-20
      • 2021-08-20
      • 2021-07-25
      • 2013-08-26
      • 2011-11-13
      • 2023-03-15
      相关资源
      最近更新 更多