-
-
Save thommay/99308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# 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