Hi,
I have two questions. first one to understand how metafields are retrieved and second to see which code is faster.
On the product page, which one is correct for product.metafileds.global.material?
1. Shopify uses a for loop for all product metafeilds that contain global, then searches for material, then displays the result.
2. Shopify uses a for loop for all metafields that contain global.material, then displays the result.
3. Shopify retrieves product.metafileds.global.material without a for loop and displays the result.
I want to show product material, dimensions, etc. on the product page.
does it make sense to use metafields for each like:
{{ product.metafileds.global.material }}
{{ product.metafileds.global.diemensions }}
OR
use one JSON string metafield that contains all information
OR
use a for loop and if statement for tag in product.tags
{% for tag in product.tags %}
{% assign first_part = tag | split: ":" | first %}
{% if first_part == "material" %}
<tr>
<td>material</td
<td>{{ tag | split: ":" | last }}</td>
<tr>
{% elsif first_part == "dimensions" %}
<tr>
<td>dimensions</td>
<td>{{ tag | split: ":" | last }}</td>
</tr>
.
.
.
{% endif %}
{% endfor %}
I've read everywhere that tags are faster to retrieve than metafields, but since I'm calling a specific metafield rather than using a for loop and an if condition to get the information, isn't a metafield faster to retrieve?
Thank you for taking the time to explain.
Solved! Go to the solution
This is an accepted solution.
Metafields are just that, fields. There are no loops involved here, just a direct access.
Your #3 solution works, and the code below is what you should use:
{{ product.metafileds.global.material }} {{ product.metafileds.global.diemensions }}
Let me know if you have other questions!
Thank you so much for the quick answer.
User | Count |
---|---|
25 | |
23 | |
22 | |
19 | |
10 |