Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Accessing metafield values — append .value or not?

Accessing metafield values — append .value or not?

mrogers
Shopify Partner
4 0 1

I have a strange situation.

 

Last fall I developed a theme for a client using Online Store 2.0 and the Dawn theme as a base. The project went to sleep for a few months for unrelated business reasons, but the theme itself was working fine when I left it. When I went to work on it again today, I find that none of the metafields in the liquid templates are printing, and any conditional logic based on metafields was broken.

 

I had originally used the syntax from the API documentation to access metafields (resource.metafields.namespace.my_field.value) — again, this worked when I left the project two months ago, but no longer works today. What *does* work today is to remove the .value from the end (resource.metafields.namespace.my_field).

 

Removing the .value fixes all the issues in my templates and the site renders properly. But it's very disconcerting that the site could break seemingly randomly, and that I'm now accessing the metafields object contrary to the documentation.

 

I'd really like to understand what happened — any theories or insights would be much appreciated!

Reply 1 (1)

vsouza
Shopify Partner
3 0 0

Hi,

 

I have a similar issue, in my case on some files (.liquid) inside Snippets folder needs to use the .value and others I can use otherwise will get 'null'.

 

Example: {{selected_variant.metafields.namespace.value}}

 

Does anybody know whats happening here?