Equivalence in IF doesn't seem to function?

Topic summary

Issue: A Liquid if comparison (review.id == this_id) in a Shopify blog template failed even though values looked identical in debug output. The template builds product-specific ID lists by splitting strings (“|”, “^”, “,”) and loops through blog.articles to find matches.

Diagnosis suggestions: Verify both variables’ exact values and types, trim whitespace, and add debug prints around the comparison. The helper emphasized subtle string differences (e.g., spaces) as a likely cause.

Resolution: The root cause was stray whitespace. Applying the Liquid strip filter to both review.id and this_id immediately before the comparison made the equality check succeed.

Outcome: Problem solved; the matching logic now works as intended. No further changes to the rendering logic were needed. The thread is resolved.

Summarized with AI on January 14. AI used: gpt-5.

I have what seems to be a straightforward if statement that SHOULD be working. I’m throwing in debug code and it still looks like it should work – but isn’t!

We’re using a modified blog as a place for our external reviews (reviews we enter ourselves) and want to list the articles by product type first, then sequentially. To that end, we build an “array” of article IDs that correspond to each products.

That being said, here’s the code:

  <h7>{{ pro_review_by_product }}</h7>
  {% assign pro_review_by_product = pro_review_by_product | split: "|" %}
  {% for pro_review in pro_review_by_product %}
    {% assign pro_review_meta = pro_review | split: "^" %}
    <h2>{{ pro_review_meta[0] }}</h2>
    {% assign pro_review_ids = pro_review_meta[1] | split: "," %}
    {% for this_id in pro_review_ids %}
      <b>Looking for: "{{ this_id }}"</b>
      {% for review in blog.articles %}
        <br />"{{ review.id }}"
        {% if review.id == this_id %}    _**<<<<<-- NOT FUNCTIONING**_
          <h1>MATCH FOUND!?</h1>
          {% assign use_featured_card = false %}
          {% for tag in review.tags %}
            {% if tag=="featured" %}
              {% assign use_featured_card = true %}
              {% break %}
            {% endif %}
          {% endfor %}
          {% if use_featured_card==true %}
            {% render 'pro-review-card-featured_SNIP', review: review %}
          {% else %}
            {% render 'pro-review-card_SNIP', review: review %}
          {% endif %}
          {% break %}
        {% endif %}
      {% endfor %}
    <br />
    {% endfor %}
    <br /><br />
  {% endfor %}

… and here’s what it is outputting:

I put quotes around the strings to ensure there wasn’t any extraneous data. I tried the to_s and the to_i filter on both, thinking it was some unseen type issue but no joy.

I am very new to Liquid, so all help would be appreciated!

Hi @kallenconsult ,
This is Theodore from PageFly - Shopify Page Builder App.
For solving the problem about the The Equivalence In IF Doesn’t Seem To Function?, let’s try this solution:

The if statement comparing review.id and this_id likely fails due to subtle string differences - check they are the same type, trim whitespace, print values before comparing, use strict comparison, and check for typos. Wrapping the if statement in {% raw %}{% endif %}{% endraw %} tags may help. Debug prints around the if statement will reveal where the mismatch occurs. Carefully verifying the variable types, values, and comparison will uncover what’s causing the if statement to unexpectedly fail.

I’ll be so happy if my suggestion can help to solve your problem. If you have any further questions, please feel free to tell me.
Best regards,
Theodore | PageFly

I could have sworn I had done a strip filter on both, but I must have done it somehow differently. Your suggestion that the showing them in HTML wasn’t as valid a test as I thought was indeed the key. I did a strip filter on both right before the comparison and it worked.

Thanks!