Skip to content

Instantly share code, notes, and snippets.

@thommay
Forked from adamhjk/MVC_in_chef.rb
Created April 21, 2009 18:42
Show Gist options
  • Save thommay/99308 to your computer and use it in GitHub Desktop.
Save thommay/99308 to your computer and use it in GitHub Desktop.
###
# Fragile, embedded, deeply tied
###
<% search("foo").each do |n| -%>
stuff with <%= n %>
<% end %>
###
# Less fragile, not embedded
# In a recipe
###
foo_servers = search("foo")
template "foo" do
variables(
:foo_servers => foo_servers
)
end
# In your template
<% @foo_servers.each do |n| -%>
stuff with <%= n %>
<% end %>
# The advantage of the latter is that you can now change what @foo_servers contains
# at your whim. You could also pass foo_servers around to N different templates, each
# one doing something different with the data. ie: if you had two templates that both
# need foo_servers, you simply pass the reference to foo_servers around.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment