Andrew B Schultz
Andrew B Schultz

Reputation: 1512

Liquid Variable not being rendered inside {% if %}

I have the following liquid code. The searchTerm variable doesn't function properly inside of the if statement. If I hard-code the if statement to something that will work, I can access the value of the searchTerm variable in the 2nd h4 you see here, so I know it's being populated.

The if statement is somehow not reading it correctly - it always evaluates to false, even if it should be true. Am I using the searchTerm variable wrong inside the if statement?

EDIT: I think the issue is that the searchTerm variable has quotation marks in the string - liquid seems to be including them somehow in the string and escaping them. When I print the searchTerm variable, it literally prints "variable" with the quotation marks included. I'm at a loss for how to remove them, because I don't know how to escape them so I can reference them properly in liquid.

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

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

Upvotes: 0

Views: 631

Answers (1)

MikeTheReader
MikeTheReader

Reputation: 4190

The value you're sending in as term may have quotes around it. Make sure it doesn't as the quotes will be included in the literal value for searchTerm. :)

Upvotes: 1

Related Questions