I’m trying to create a loop to generate ‘rows’ for a table using metafields for each of the data points. I know there’s a tablerow loop in Liquid, however it won’t work well with the current codebase since we’re not able to use HTML tables due to very specific technical limitations.
That being the case, I’m trying to generate rows as divs dynamically using the forloop index as a variable on the metafields themselves, because the only thing that changes on the metafield handle for each datapoint is the number as you can see in the code below. That way the logic can be written once instead of having to do it in a super repetitive way (and also not dynamic).
The issue is that when the page is rendered, instead of rendering the value of the metafields themselves, it’s rendering the metafield path as a string directly to the front end:
{% assign rowLimit = product.metafields.global.row-count %}
{% for i in (1..rowLimit) %}
{% capture tableLength %}
product.metafields.global.table-length-{{ i }}
{% endcapture %}
{% capture tableWidth %}
product.metafields.global.table-width-{{ i }}
{% endcapture %}
{% capture tableThickness %}
product.metafields.global.table-thickness-{{ i }}
{% endcapture %}
{% capture tableVolume %}
product.metafields.global.table-volume-{{ i }}
{% endcapture %}
{% if tableLength %}
{{ tableLength }}
{{ tableWidth }}
{{ tableThickness }}
{{ tableVolume }}
{% endif %}
{% endfor %}
I believe the liquid variable is being processed and returning the variable’s value as a string which is then the output to the browser. How can I process the value of the variable and then use it inside {{ }} for example to process the actual metafield path instead of a string?
I would really appreciate it if you would help me figure this out!
I’m having a similar problem but this approach isn’t solving it for me. It’s either returning nothing or weird obj like {“11053187399853”=>“rx requested 2x”}. Would greatly appreciate any advice.
My problem: I want to store specialized line item fulfillment statuses that a user will see when viewing an order. (Client has a complicated flow for insurance and prescription verifications with like a dozen Salesforce statuses.) The LineItem object does not have metafields, so I want to store them in Orders using the line item ID as the metafield key.
The idea is that I can then programmatically update statuses via API and display them via Liquid. However, I’m having a devil of a time getting the liquid side to work.
I tried your method, but it would not return a value. When I tried a few different workarounds, the best I’ve come up with gives me a strangely formatted string instead: {“11053187399853”=>“rx requested 2x”}
For anyone else who has similar problem. The arrow function looking thing I’m pretty sure was Ruby hash rocket getting passed b/c of bad key.
Source of my problem was type. The key was an integer instead of string, and my attempts to convert to string were failing quietly. But not entirely, so I was getting hash rocket instead of the value.