Solved

Equivalence in IF doesn't seem to function?

kallenconsult
Excursionist
41 0 10

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:

Screenshot 2023-11-05 at 1.27.03 AM.png

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!

 

Accepted Solution (1)

PageFly-Theodor
Navigator
497 67 75

This is an accepted solution.

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

Please let me know if it works by giving it a Like or marking it as a solution!


PageFly - #1 Page Builder for Shopify merchants.


All features are available from Free plan. Live Chat Support is available 24/7.

View solution in original post

Replies 2 (2)

PageFly-Theodor
Navigator
497 67 75

This is an accepted solution.

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

Please let me know if it works by giving it a Like or marking it as a solution!


PageFly - #1 Page Builder for Shopify merchants.


All features are available from Free plan. Live Chat Support is available 24/7.

kallenconsult
Excursionist
41 0 10

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!