Skip to content

Instantly share code, notes, and snippets.

@brycethornton
Created March 27, 2011 18:52
Show Gist options
  • Save brycethornton/889467 to your computer and use it in GitHub Desktop.
Save brycethornton/889467 to your computer and use it in GitHub Desktop.
I'm pretty confused about how liquid treats hashes in a template.
# Controller (simplified):
def show
vars = {}
vars['status_dates'] = @system.get_statuses_by_date
@template = Liquid::Template.parse(@system.theme.source)
render :text => @template.render( vars )
end
# status_dates is a hash formatted like so:
# {date => {:level => 'good', :description => 'All good', :statuses => [status_object1, status_object2]}, date2 => {...}}
# Liquid Template (simplified):
{% for date, date_values in status_dates %}
This is the date: {{date}}
This is the level: {{date_values[:level]}}
{% for status in date_values[:statuses] %}
This is the status: {{status.description}}
{% endfor %}
{% endfor %}
# This does not work at all. I've tried many different variations and can't seem to figure it out. Any help?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment