Open reggi opened 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 %}
Just to make one final experiment
{% assign array = "Thomas Reggi" | split: " " %}
{{ array.size | json }}
{{ array["size"] | json }}
this will output, as expected
2
null
When there's a metafield with a
key
set tosize
, the variable renders the actual size of thenamespace
object rather then themetafield
with thekey
set to size. Any metafield with akey
set tosize
is going to render1
.You can see that
.size
is in liquids documentation.Example:
It is expected is that I should get my
metafield
value
.