Liquid, JavaScript, themes, sales channels
My site had suddenly started throwing an error, despite no updates to my code base.
The error says:
Expected input to be a String but got Metafields::StringDrop
The line in which the error is occurring is in a snippet called team-badge
{{ rotator_image | asset_url | img_tag: "", 'badge-rotator-img'}}
The snippet above is called by a section file with the following line:
{%- render 'team-badge', rotator_image: collection.metafields.global.treasure_badge_asset, badge_url: collection.metafields.global.treasure_badge_url -%}
We use this team-badge throughout the site. The error only occurs when using the metafields.
I've tried Googleing the error, however, the only pages that pop up belong to our site! So, I'm not finding any help in the Googel-verse. "Metafields::StringDrop" isn't anywhere I can find either.
Again, this is an error which did not exist, and then without any updates, started appearing.
Any help would be greatly appreciated.
Solved! Go to the solution
This is an accepted solution.
Hi Alex,
Sasha here from Metafields Guru team.
I've been contacted by another Shopify merchant experiencing a similar issue earlier. Luckily, I managed to figure out what exactly caused the error and how to get it fixed.
The reason for this error is the recent update in Shopify Liquid. The "old" version of Liquid would require a code like this to retrieve a metafield value:
{{ resource.metafields.namespace.key }}
The same code would return a metafield object in the "new" version of Liquid. And that's where the issue comes from. Since your theme uses "old" Liquid code, it returns an object while the Liquid filters (the URL filter, in this case) expect the variable passed to be a string.
So, in order to have the issue resolved, you may want to update your Liquid code and use the proper syntax of "new" Liquid standard:
{{ resource.metafields.namespace.key.value }}
Note that ".value" part added after the metafield key. As we're dealing with the object, it helps us to retrieve the metafield value and pass it as a variable for the URL filter.
Hope this helps!
A message to other Shopify merchants looking to have a similar issue resolved: if you don't know how to use Liquid or customize your theme, don't worry. In this case, you may want to consider contacting a developer who has set up the store for you and asking them to update your store's theme code.
Are using an app to manage the metafields?
If you didn't change anything metafields related in your code, could be that the app your are using have been updated and maybe it is the reason of this error.
This is an accepted solution.
Hi Alex,
Sasha here from Metafields Guru team.
I've been contacted by another Shopify merchant experiencing a similar issue earlier. Luckily, I managed to figure out what exactly caused the error and how to get it fixed.
The reason for this error is the recent update in Shopify Liquid. The "old" version of Liquid would require a code like this to retrieve a metafield value:
{{ resource.metafields.namespace.key }}
The same code would return a metafield object in the "new" version of Liquid. And that's where the issue comes from. Since your theme uses "old" Liquid code, it returns an object while the Liquid filters (the URL filter, in this case) expect the variable passed to be a string.
So, in order to have the issue resolved, you may want to update your Liquid code and use the proper syntax of "new" Liquid standard:
{{ resource.metafields.namespace.key.value }}
Note that ".value" part added after the metafield key. As we're dealing with the object, it helps us to retrieve the metafield value and pass it as a variable for the URL filter.
Hope this helps!
A message to other Shopify merchants looking to have a similar issue resolved: if you don't know how to use Liquid or customize your theme, don't worry. In this case, you may want to consider contacting a developer who has set up the store for you and asking them to update your store's theme code.
Thanks! This solved the problem.
How do I get notified of fundamental changes to languages like Liquid? I can't see any mention of this in the changelog linked.
@quartzstudio you can see changes to the Shopify platform here: https://shopify.dev/changelog
It lets you enter an email so you can be updated when there's a change.
Hi guys!
Sorry for a late reply, I didn't see the notifications for some reason.
It's really nice to hear that my reply helped you to resolve the same issue on your stores 😁
Best regards,
Sasha Kachkovskyi
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024