reggi / shopify

Just a place to track issues and feature requests that I have for shopify
3 stars 1 forks source link

Metafield where key is "size" will always be 1 #16

Open reggi opened 9 years ago

reggi commented 9 years ago

When there's a metafield with a key set to size, the variable renders the actual size of the namespace object rather then the metafield with the key set to size. Any metafield with a key set to size is going to render 1.

You can see that .size is in liquids documentation.

Example:

collection.metafields.jumbotron.title: null
collection.metafields.jumbotron.size: 1

It is expected is that I should get my metafield value.

reggi commented 9 years ago

I just did a little more testing and found the following:

{{ collection.metafields.jumbotron["size"] | json }}
{{ collection.metafields.jumbotron.size | json }}
{{ collection.metafields.jumbotron["title"] | json }}
{{ collection.metafields.jumbotron.title | json }}

If all of these variables are set as string you will get this output

"Size Value"
"Size Value"
"Title Value"
"Title Value"

If none of them are set, you get this

null
1
null
null

Sometimes the second value renderd as 2 or another number, not sure why.

One solution could be to always use bracket syntax like this

{{ collection.metafields.jumbotron["size"] | json }}

especially when using a metafield in a conditional statment

{% if collection.metafields.jumbotron["size"] %}
{% endif %}
reggi commented 9 years ago

Just to make one final experiment

{% assign array = "Thomas Reggi" | split: " " %}
{{ array.size | json }} 
{{ array["size"] | json }}

this will output, as expected

2
null