Access to a value into a hash

1,617 views
Skip to first unread message

lphm

unread,
Apr 6, 2011, 8:03:51 AM4/6/11
to Liquid Templates
Hello

I pass a ruby Hash into liquid context (by assigns) :

:my_hash => {:a => 'value_a', :b => 'value_b'}

But I cannot access to values into Hash in liquid template :

{{ my_hash['a'] }} => Give nothing

{{ my_hash }} => Give a string likely .inspect ruby method

How to access to a key/value into Hash ?

Best regards.

Tobias Lütke

unread,
Apr 6, 2011, 6:46:38 PM4/6/11
to liquid-t...@googlegroups.com, lphm
don't use symbols in liquid. Symbols go into the global hash table and in a user fascing system they would leak memory every time you use a new one.

In any case this should work:


'my_hash' => {'a' => 'value_a', 'b' => 'value_b'}


{{ my_hash['a'] }} or more liquidy' {{ my_hash.a }}


Regards
-- tobi



--
You received this message because you are subscribed to the Google Groups "Liquid Templates" group.
To post to this group, send email to liquid-t...@googlegroups.com.
To unsubscribe from this group, send email to liquid-templat...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liquid-templates?hl=en.


lphm

unread,
Apr 10, 2011, 6:36:05 AM4/10/11
to Liquid Templates
Thank you for your response.

Best regards.
Reply all
Reply to author
Forward
0 new messages