【问题标题】:Liquid Variable not being rendered inside {% if %}液体变量未在 {% if %} 内呈现
【发布时间】:2017-10-31 19:09:55
【问题描述】:

我有以下液体代码。 searchTerm 变量在 if 语句中无法正常工作。如果我将 if 语句硬编码为可以工作的东西,我可以访问您在此处看到的第二个 h4 中的 searchTerm 变量的值,所以我知道它正在被填充。

if 语句在某种程度上没有正确读取它 - 它总是评估为假,即使它应该是真的。我在 if 语句中使用了错误的 searchTerm 变量吗?

编辑:我认为问题在于 searchTerm 变量在字符串中有引号 - 液体似乎以某种方式将它们包含在字符串中并转义它们。当我打印 searchTerm 变量时,它会直接打印带有引号的“变量”。我不知道如何删除它们,因为我不知道如何逃避它们,所以我可以在液体中正确引用它们。

{% assign searchTerm = request.params['term'] %}

{% if firstName contains searchTerm %}
 <item>
  <h4> {{item.usc_firstname}} </h4>
  <h4> {{searchTerm}} </h4>
  <hr width = "100%">
 </item>
{% endif %}

【问题讨论】:

  • 名字从何而来?您显示的是 searchTerm,但不是名字。
  • 嘿迈克,是的,它来自应用程序。没问题。
  • 那么 searchTerm 和 firstName 不起作用时的值是多少?
  • 刚刚添加了一个编辑 - 我认为这是 searchTerm 中的引号问题。不知道他们为什么在那里。它不起作用的一个实例是 firstName = draw 和 searchTerm = "drew" (包括引号)。
  • 您的 URL 中是否包含引号?换句话说,您发送的术语的原始值是多少?

标签: javascript liquid


【解决方案1】:

您作为term 发送的值可能带有引号。确保它没有,因为引号将包含在 searchTerm 的文字值中。 :)

【讨论】:

  • 这就是问题 Mike - 我的查询字符串参数中有引号,它被传递到液体变量中,我不知道如何转义它们。感谢您的帮助!
猜你喜欢
  • 2011-11-07
  • 1970-01-01
  • 2021-07-15
  • 1970-01-01
  • 2011-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多