0

I would like to use a Volt::Model as a reactive dictionary in a view.

Ideally, I would like something like this:

<dl>
  {{ dictionary.each do |key, val| }}
  <dt>Term: {{ key }}</dt>
  <dd>Definition: {{ val }}</dd>
  {{ end }}
</dl>

Is this possible in Volt without using an ArrayModel?

Rick
  • 8,366
  • 8
  • 47
  • 76

3 Answers3

1

Sorry, I don't have .each_pair working in bindings in Volt yet, its on the todo list. Yea, you can use .keys.each do |key| in the mean time.

Ryan
  • 956
  • 7
  • 8
0

Figured it out. This works:

<dl>
  {{ dictionary.keys.each do |key| }}
  <dt>Term: {{ key }}</dt>
  <dd>Definition: {{ dictionary.get(key) }}</dd>
  {{ end }}
</dl>
Rick
  • 8,366
  • 8
  • 47
  • 76
0

The version in the question should almost work. You just have to use each_pair instead of each.

Torsten
  • 425
  • 4
  • 7